Skip to content

Instantly share code, notes, and snippets.

@isag
Created April 21, 2012 10:24
Show Gist options
  • Save isag/2436409 to your computer and use it in GitHub Desktop.
Save isag/2436409 to your computer and use it in GitHub Desktop.
use the treads for pool replicaes
typedef struct
{
unsigned int id;
Params *p;
}
pth;
void treatments(void *param, unsigned long s)
{
//------------//
// LOCAL COPY //
//------------//
Params *P = (Params*)param;
//------------------------------------------------------//
// OPEN A NEW FOLDER AND SAVE THE REGIONAL POOL SPECIES //
//------------------------------------------------------//
char *buffer = (char*)malloc(100);
sprintf(buffer, "SIMU_%lu",s);
mkdir(buffer, S_IRWXU); // S_IRWXU is the mode, it give read/write/search access to the user.
print_global_parameters(P, s,buffer);
P->folder = buffer;
//-----------------//
// TREATMENT LOOPS //
//-----------------//
char buffer2[100];
for(int i = 0 ; i < P->nsize ; ++i) // SIZE POOL LOOP
{
(P->pos_var)[0] = i;
for(int j = 0 ; j < P->nfert ; ++j) // FERTILITY LOOP
{
(P->pos_var)[1] = j;
// NUMBERS OF REPLICATES
//-----------------------
int n_threads = P->nrep;
// THREADS
//--------
pthread_t threads[n_threads];
// CREATE THE THREADS
//-------------------
int k = 0;
for (; k < n_threads; ++k)
{
pth *param = (pth*) malloc(sizeof(pth));
param->id = k + 1;
param->p = P;
pthread_create(&threads[k], NULL, replicates, (void*)param);
free(param);
}
// WAIT FOR THE THREADS TO END
//----------------------------
for (k = 0 ; k < n_threads; ++k)
{
pthread_join(threads[k], NULL);
}
} // END FERTILITY LOOP
} // END SIZE POOL LOOP
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment