我是一位使用OpenMP和C++的新手。我正在做一个简单的函数,使用for循环加载两个数组。这些数组被定义为复杂的。使用OpenMP的复杂类型
#include <omp.h>
#include <iostream>
#include <stdlib.h>
#include <complex>
#define CHUNKSIZE 10
#define N 100
using namespace std;
int main (int argc, char *argv[])
{
int nthreads, tid, i, chunk;
complex<double> a[N], b[N], c[N];
/* Some initializations */
for (i=0; i < N; i++)
a[i].real() = b[i].real() = i * 1.0;
chunk = CHUNKSIZE;
#pragma omp parallel shared(a,b,c,nthreads,chunk) private(i,tid)
{
tid = omp_get_thread_num();
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
printf("Thread %d starting...\n",tid);
#pragma omp for schedule(dynamic,chunk)
for (i=0; i<N; i++)
{
c[i] = a[i] + b[i];
printf("Thread %d: c[%d]= %e\n",tid,i,c[i]);
}
} /* end of parallel section */
}
当我编译,我得到这样的警告:
omp_complex.cpp:43:警告:不能通过非POD类型的对象的结构的std ::复杂'到“...”;呼叫将在运行时中止
如果我运行a.out,屏幕上会显示“非法指令”消息。我试图找出发生了什么,但我没有找到任何好的参考。有谁知道在OpenMP指令中是否允许复杂类型?
这与OpenMP没有任何关系。下一次,将您的代码降至最低以解决问题! – 2012-02-16 13:04:11