Memory problems with OpenMP


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.exposureN(i,j);

/* the second part */

for(j=0; j<epidata.susceptible.size(); ++j) {
result = result + betastar(parms,epidata,, * 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?


Chris Jewell

Hi Chris,

This code looks ok, so I’m not sure what’s wrong. Can you please send a note to and include the full source (or a pointer to it if it’s too large) as well as build instructions. Also, please include the compiler version and OS.