openMP 只运行一个线程?
我在 main:
int main(int argv, char **argc)
{
// Get multi-CPU/multi-GPU data
int num_gpus;
cudaGetDeviceCount(&num_gpus);
printf("### Number of host CPUs:\t%d\n", omp_get_num_procs());
printf("### Number of CUDA devices:\t%d\n", num_gpus);
omp_set_num_threads(num_gpus);
#pragma omp parallel
{
unsigned int cpu_thread_id = omp_get_thread_num();
printf("### (CPU thread %d)\n",cpu_thread_id);
test(cpu_thread_id, num_gpus);
}
}
和测试函数中有这段代码:
void test(unsigned int cpu_thread_id, int num_gpus)
{
printf("### Using CUDA device %d, GPU = %d\n", cpu_thread_id, num_gpus);
}
即使我得到了输出:
### Number of host CPUs: 8
### Number of CUDA devices: 4
### (CPU thread 0)
### Using CUDA device 0, GPU = 4
但我期望有更多像这样的线程:
### (CPU thread 1)
### Using CUDA device 1, GPU = 4
### (CPU thread 2)
### Using CUDA device 2, GPU = 4
### (CPU thread 3)
### Using CUDA device 3, GPU = 4
为什么其他三个线程没有运行?
提前致谢。
I have this code in the main:
int main(int argv, char **argc)
{
// Get multi-CPU/multi-GPU data
int num_gpus;
cudaGetDeviceCount(&num_gpus);
printf("### Number of host CPUs:\t%d\n", omp_get_num_procs());
printf("### Number of CUDA devices:\t%d\n", num_gpus);
omp_set_num_threads(num_gpus);
#pragma omp parallel
{
unsigned int cpu_thread_id = omp_get_thread_num();
printf("### (CPU thread %d)\n",cpu_thread_id);
test(cpu_thread_id, num_gpus);
}
}
and the test function:
void test(unsigned int cpu_thread_id, int num_gpus)
{
printf("### Using CUDA device %d, GPU = %d\n", cpu_thread_id, num_gpus);
}
Even I got the output:
### Number of host CPUs: 8
### Number of CUDA devices: 4
### (CPU thread 0)
### Using CUDA device 0, GPU = 4
But I expected to have more threads like this:
### (CPU thread 1)
### Using CUDA device 1, GPU = 4
### (CPU thread 2)
### Using CUDA device 2, GPU = 4
### (CPU thread 3)
### Using CUDA device 3, GPU = 4
Why the other three threads are not running?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论