Home Ask Login Register

Developers Planet

Your answer is one click away!

Laetis February 2016

call function in openmp parallelized loop

I am new to OpenMP and I have a loop that I want to parallelize with OpenMP. Inside the parallel loop a subroutine is called. Here my code:

#pragma omp parallel for shared(dir,utilitiespath,frequency,solvent,Method,dispersion)  private(beginning,file_cp2k,file_geo,file_energy)
    file_cp2k="conformer"+ QString::number(i) +".inp";
    file_geo= "conformer" +  QString::number(i) + "_geoMM.sdf";
    file_energy=dir+ "conformer" + QString::number(i)  + "_enerSE";
    cout<<"loop "<<i<<" time "<<beginning<< endl;
    int n_atom=Makecp2kOptInput(file_geo, file_cp2k, dir,utilitiespath, frequency, solvent, Method,dispersion);

I get the following error:

* Error in `./ChemAliveMolOpt': double free or corruption (fasttop): 0x00000000018d7c00 * Aborted (core dumped)

If I remove the call to the subroutine there is no problem.

How should I proceed to parallelize the loop properly?



Sven Nilsson February 2016

All code that the OpenMP-enabled loop executes must be thread safe. Your subroutine is probably not thread safe. Thread safety essentially means that you synchronize the access to all global/shared objects.

This is not an easy topic, so I recommend you study thread safety and mutex-based synchronization in order to solve your problem.

Post Status

Asked in February 2016
Viewed 2,154 times
Voted 11
Answered 1 times


Leave an answer

Quote of the day: live life