これが私のコードです:
main.cpp
#include <header.h>
#include <Eigen/Dense>
int main{
int result(100);
VectR M(100) = something; // VectR defined in header.h
VectR N(100) = something else;
#pragma omp parallel private(var,i,R) shared(M,N,result)
{
#pragma omp for
for(int i = 0 ; i < 100 ; ++i){
result(i) = somefunction(M,N(i));
}
}
}
somefunction別のファイルで定義されている は、ベクトル全体を読み取る (書き込みはしない) 必要がありますM。
header.h:
#include <Eigen/Dense>
using namespace Eigen;
typedef double REAL;
typedef Eigen::Matrix<REAL, Eigen::Dynamic, 1> VectR;
int somefunction(const VectorR&, const VectorR&)
M複数のスレッドがinの特定の要素にsomefunction同時にアクセスしないようにするにはどうすればよいですか? いくつかの考え:
- M が読み取られるファイルに
#pragma omp criticaloratomicディレクティブを直接配置できますか/すべきですか?somefunction 私の最初のアイデアは、ディレクティブ
Mの句によって各スレッドに独自の完全なコピーを与えることでした。ただし、コンパイル時に次のエラーが発生します。firstprivate(M)parallelmain.cpp: In function âint somefunction(const VectorR&, const VectorR&)â:main.cpp:xx: error: âMâ has reference type for âfirstprivateâ