如果删除 . #pragma omp parallel for
_ 我猜测原因是多个线程尝试写入变量或. 我该如何解决?有没有办法告诉它变量是共享的?还是通常有另一种方法可以并行执行此循环。我对`openmp完全陌生,这是我第一次使用它。*** glibc detected *** ./testBin: double free or corruption (!prev): 0x0c43d8d8 ***
core dumped
omega, ell, ....
lineVec
#include <omp.h>
int main( int argc , char **argv )
{
vector <vector<string>> fileVec;
//some code that reads in a CSV file lines into elements of fileVec
//variables constituting a line:
//my_float has been typedef to be a high precision class in real code
my_float omega;
my_float ell;
my_float init1Real;
my_float init1Imag;
my_float dinit1Real;
my_float dinit1Imag;
my_float init2Real;
my_float init2Imag;
my_float dinit2Real;
my_float dinit2Imag;
#pragma omp parallel for private(lineVec,fileVec,ell,omega,init1Real,init1Imag,dinit1Real,dinit1Imag,init2Real,init2Imag,dinit2Real,dinit2Imag)
for (size_t i=0; i< fileVec.size(); i++)
{
lineVec=fileVec[i];
ell=lineVec[0];
omega=lineVec[1];
init1Real=lineVec[2];
init1Imag=lineVec[3];
dinit1Real=lineVec[4];
dinit1Imag=lineVec[5];
init2Real=lineVec[6];
init2Imag=lineVec[7];
dinit2Real=lineVec[8];
dinit2Imag=lineVec[9];
// cout<<"OUTPUT ell=" << ell<< " omega=" << omega <<" init1Real="<<init1Real<<endl;
//do some other calc involving these variables
}
}