Skip to content

Instantly share code, notes, and snippets.

@isag
isag / treat_th.c
Created April 21, 2012 10:24
use the treads for pool replicaes
typedef struct
{
unsigned int id;
Params *p;
}
pth;
void treatments(void *param, unsigned long s)
{
//------------//
@isag
isag / create_pool.c
Created April 12, 2012 08:37
A way to create a species pool from assembly process
void create_assembled_pool(Params *p, double **pool, int divpool, double fert)
{
restart:;
// define and initialize the ecosystem list
//-----------------------------------------
sll ecosys;
sll_init(&ecosys,(void*)free_species);
// create the basal resources
double **select_subpool(Params *p, double **pool,int nrows,int nrows_sub)
{
int positions[nrows];
for(int i = 0 ; i < nrows ; ++i) positions[i] = i;
// shuffle the vector
//-------------------
knuth_shuffle((void*)positions, nrows, p->rng, sizeof(int*));
for (int i = 0 ; i < nrows ; ++i) printf("%d\t",positions[i]);
printf("\n");
@isag
isag / struct_to_array.c
Created March 31, 2012 15:36
EAM - Moving the data inside a struct to an array
// \param p0 The structure to copy in an array.
// \param param_sp An array of double with space for at least 6 elements (48 bytes).
inline double *tr_sp_array(ParamSP *p, double *param_sp)
{
param_sp[0] = (double)p->cycle_num;
param_sp[1] = (double)p->number;
param_sp[2] = (double)p->ab;
param_sp[3] = (double)p->pc;
param_sp[4] = p->input;
param_sp[5] = p->mass;
@isag
isag / struct_to_array.c
Created March 31, 2012 15:17
EAM - Moving the data inside a struct to an array
// \param p0 The structure to copy in an array.
// \param param_sp An array of double with space for at least 6 elements (48 bytes).
inline double *tr_sp_array(ParamSP *p, double *param_sp)
{
param_sp[0] = (double)p->cycle_num;
param_sp[1] = (double)p->number;
param_sp[2] = (double)p->ab;
param_sp[3] = (double)p->pc;
param_sp[4] = p->input;
param_sp[5] = p->mass;
double *tr_sp_array(ParamSP *p0)
{
ParamSP *p = (ParamSP*)malloc(sizeof(ParamSP));
memcpy((void*)p,(void*)p0,sizeof(ParamSP));
double *param_sp = (double*)malloc(6*sizeof(double));
param_sp[0] = (double)p->cycle_num;
param_sp[1] = (double)p->number;
param_sp[2] = (double)p->ab;
int rand_a_b(gsl_rng *rng, int a, int b)
{
return((gsl_rng_uniform(rng))%(b-a)+a);
}