【发布时间】:2014-09-25 23:54:28
【问题描述】:
我使用 Ubuntu 并编写了几行代码。但它只创建一个线程。当我在终端上运行 nproc 命令时,输出为 2。我的代码如下
int nthreads, tid;
#pragma omp parallel private(tid)
{
tid = omp_get_thread_num();
printf("Thread = %d\n", tid);
/* for only main thread */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
}
输出:
Thread = 0
Number of threads = 1
我怎样才能做并行?
【问题讨论】:
标签: c++ multithreading parallel-processing openmp