0

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)
for(i=1;i<=n_conformers;i=i+1)
{
    time(&beginning);
    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?

Thanks

3
  • Make your subroutine call sequential. Also, calling time won't work as you're expecting it to, probably. Commented Feb 8, 2016 at 12:20
  • @erip Well this is the subroutine that is long and I would like to have several instance of it running Commented Feb 8, 2016 at 14:29
  • Seeing as you're listing the behavior of every variable, you should also make i private and n_conformers shared. However, without us knowing what the function Makecp2kOptInput does and how it interacts with these variables, we can't help you further. Commented Feb 8, 2016 at 15:51

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.