acc_set_device_num && acc_get_device_num例程
void acc_set_device_num( int, acc_device_t );
描述
在指定类型的所有设备中, acc_set_device_num 告诉运行时库环境用哪一个设备。如果 devicenum 的值为负,运行时环境将恢复到编译器自行定义的默认行为。如果第二个
参数是零,选定的设备编号将应用到所有的加速器类型。
int acc_get_device_num( acc_device_t );
描述
acc_get_device_num 例程返回一个与指定类型设备编号相对应的整数,该设备将执行下一个加速器 parallel 区域或 kernels 区域。
setgetdevicenum.c代码
1 /* 文件名: setgetdevicenum.c
2 * 功能 : 测试函数acc_get_device_num(.)和acc_get_num_devices(.).
3 */
4 #include<stdio.h>
5 #include"openacc.h"
6 int main()
7 {
8 int num = -888, cdev;
9 int i;
10 num = acc_get_num_devices(acc_device_default);
11 printf(" nothing set, #device_dafault = %d\n", num);
12 num = acc_get_num_devices(acc_device_nvidia);
13 printf(" nothing set, #device_nvidia = %d\n", num);
14 num = acc_get_num_devices(acc_device_xeonphi);
15 printf(" nothing set, #device_xeonphi = %d\n", num);
16 cdev = acc_get_device_num(acc_device_xeonphi);
17 printf(" nothing set, device_xeonphi = %d\n", cdev);
18 acc_set_device_num(1, acc_device_default);
19 cdev = acc_get_device_num(acc_device_default);
20 printf("default 1 set, device_dafault = %d\n", cdev);
21 acc_set_device_num(1, acc_device_default);
22 cdev = acc_get_device_num(acc_device_nvidia);
23 printf("default 1 set, device_nvidia = %d\n", cdev);
24 acc_set_device_num(1, acc_device_nvidia);
25 cdev = acc_get_device_num(acc_device_default);
26 printf(" nvidia 1 set, device_default = %d\n", cdev);
27 acc_set_device_num(1, acc_device_nvidia);
28 cdev = acc_get_device_num(acc_device_nvidia);
29 printf(" nvidia 1 set, device_nvidia = %d\n", cdev);
30 num = acc_get_num_devices(acc_device_nvidia);
31 for(i = -num; i< 3*num; i++)
32 {
33 acc_set_device_num(i, acc_device_nvidia);
34 cdev = acc_get_device_num(acc_device_nvidia);
35 printf("i =%2d, cdev = %d\n",i, cdev);
36 }
37 return 0;
38 }
编译信息