我有使用OpenMP和C++的代码.代码正确执行但有时会挂起.我正在使用部分.你能告诉我这是什么问题吗?我尝试了几件事,但没有一件工作,比如将变量从私有变为共享.
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#define N 50
//gcc -fopenmp -o e3 e3.c
int main (int argc, char *argv[])
{
int i, nthreads, tid, section;
float a[N], b[N], c[N];
void print_results(float array[N], int tid, int section);
/* Some initializations */
for (i=0; i<N; i++)
a[i] = b[i] = i * 1.0;
#pragma omp parallel private(c,i,tid,section)
{
tid = omp_get_thread_num(); //FIXME: how to get the thread id?
if (tid == 0)
{
nthreads = omp_get_num_threads(); //FIXME: how to get …Run Code Online (Sandbox Code Playgroud)