コードを並行して実行しようとしていますが、openmp に関連するプライベート/共有などと混同しています。私は c++ (msvc12 または gcc) と openmp を使用しています。
コードは、並列で実行する必要があるブロックと、それに続くすべての並列処理が完了したときに実行する必要があるブロックで構成されるループを反復処理します。並列処理がどの順序で処理されるかは問題ではありません。コードは次のようになります。
// some X, M, N, Y, Z are some constant values
const int processes = 4;
std::vector<double> vct(X);
std::vector<std::vector<double> > stackVct(processes, std::vector<double>(Y));
std::vector<std::vector<std::string> > files(processes, M)
for(int i=0; i < N; ++i)
{
// parallel stuff
for(int process = 0; process < processes; ++process)
{
std::vector<double> &otherVct = stackVct[process];
const std::vector<std::string> &my_files = files[process];
for(int file = 0; file < my_files.size(); ++file)
{
// vct is read-only here, the value is not modified
doSomeOtherStuff(otherVct, vct);
// my_files[file] is read-only
std::vector<double> thirdVct(Y);
doSomeOtherStuff(my_files[file], thirdVct(Y));
// thirdVct and vct are read-only
doSomeOtherStuff2(thirdVct, otherVct, vct);
}
}
// when all the parallel stuff is done, do this job
// single thread stuff
// stackVct is read-only, vct is modified
doSingleTheadStuff(vct, stackVct)
}
パフォーマンスが良い場合は、「doSingleThreadSuff(...)」を並列ループに移動できますが、シングル スレッドで処理する必要があります。最も内側のループ内の関数の順序は変更できません。
#pragma omp を機能させるには、どのように宣言すればよいですか? ありがとう!