基本的に、セカンダリスレッドによって(いくつかの選択された間隔で)編集できるいくつかのグローバル変数の値に基づいていくつかの操作を実行し続けるために、マスタースレッドが必要です。何かのようなもの:
vector<int> mySharedVar;
void secondaryThreadFunction() {
Do some operations
And update mySharedVar if necessarily
}
int main() {
int count = 0;
while(true) {
count++;
if (count%100) { //> Each 100 iterations run a parallel thraed
//> RUN secondaryThreadFunction in a separateThread
}
this is the main thread that based its operation on mySharedVar
}
}
単一の並列スレッドを実行するためのopenmpコマンドはどれsecondaryThreadFunction();
ですか?
これ以外に良い方法はありますか?
#pragma omp parallel num_threads(2)
{
int i = omp_get_thread_num();
if (i == 0){
mainThread();
}
if (i == 1 || omp_get_num_threads() != 2){
secondaryThreadFunction();
}
}