// here go the calls that send data to be duplicated on other MPI processes from process 0 to others, using MPI broadcasts, but only if MPI is actually used
#ifdef MPI_VERSION
if(mpidata->mpirunning){
gconf->mpibcast(mpidata);
sconf->mpibcast(mpidata);
cid->mpibcast(mpidata);
p_scattering_angles->mpibcast(mpidata);
}
#endif
// Create this variable and initialise it with a default here, so that it is defined anyway, with or without OpenMP support enabled
// make sure all threads align here: I don't want the following loop to accidentally start for thread 0, possibly modifying some variables before they are copied by all other threads
// Giovanni, please add here in this loop code to reopen the temporary files, reread them and append them respectively to the global output and tppoan, before closing them
// Create this variable and initialise it with a default here, so that it is defined anyway, with or without OpenMP support enabled
intompnumthreads=1;
#pragma omp parallel
{
// Create and initialise this variable here, so that if OpenMP is enabled it is local to the thread, and if OpenMP is not enabled it has a well-defiled value anyway
intmyompthread=0;
#ifdef _OPENMP
// If OpenMP is enabled, give actual values to myompthread and ompnumthreads, and open thread-local output files
// To test parallelism, I will now start feeding this function with "clean" copies of the parameters, so that they will not be changed by previous iterations, and each one will behave as the first one. Define all (empty) variables here, so they have the correct scope, then they get different definitions depending on thread number
ClusterIterationData*cid_2=NULL;
FILE*output_2=NULL;
fstream*tppoanp_2=NULL;
// for threads other than the 0, create distinct copies of all relevant data, while for thread 0 just define new references / pointers to the original ones
if(myompthread==0){
cid_2=cid;
// output_2 = output;
// tppoanp_2 = tppoanp;
}else{
// this is not thread 0, so do create fresh copies of all local variables
// make sure all threads align here: I don't want the following loop to accidentally start for thread 0, possibly modifying some variables before they are copied by all other threads
#pragma omp barrier
if(myompthread==0)logger->log("Syncing OpenMP threads and starting the loop on wavelengths\n");
// ok, now I can actually start the parallel calculations