Hi,
I am having difficulty with the following code:
double compute_A2(epiParms &parms, sinrEpi &epidata) {
double result = 0.0;
int i,j;
#pragma omp parallel for default(shared) private(i,j) schedule(static) reduction(+:result)
for (i=0; i<epidata.infected.size(); ++i) {
/* this is the first part */
for (j=0; j<epidata.infected.size(); ++j) {
result = result + betastar(parms,epidata,epidata.infected.at(i).label,epidata.infected.at(j).label) * epidata.exposureN(i,j);
}
/* the second part */
for(j=0; j<epidata.susceptible.size(); ++j) {
result = result + betastar(parms,epidata,epidata.infected.at(i).label,epidata.susceptible.at(j)) * epidata.NTime(i);
}
}
return result;
}
What I want to do is to parallelise the outer for loop. epidata is a class defined in another file, as is parms. When I compile the program, I included a -mp switch for the file in which the code above exists, but not the one where the classes are defined since I was having trouble with the compiler rejecting some exception-handling commands (yes, I have --exceptions there).
The above code works fine if I omp_set_num_threads(1), but not if I use more than 1 thread - I get segfaults occurring if I do. Does anyone have any suggestions on what might be wrong?
Thanks,
Chris Jewell