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代码
/* 文件名: setgetdevicenum.c
* 功能 : 测试函数acc_get_device_num(.)和acc_get_num_devices(.).
*/
#include<stdio.h>
#include"openacc.h"
int main()
{
int num = -, cdev;
int i;
num = acc_get_num_devices(acc_device_default);
printf(" nothing set, #device_dafault = %d\n", num);
num = acc_get_num_devices(acc_device_nvidia);
printf(" nothing set, #device_nvidia = %d\n", num);
num = acc_get_num_devices(acc_device_xeonphi);
printf(" nothing set, #device_xeonphi = %d\n", num);
cdev = acc_get_device_num(acc_device_xeonphi);
printf(" nothing set, device_xeonphi = %d\n", cdev);
acc_set_device_num(, acc_device_default);
cdev = acc_get_device_num(acc_device_default);
printf("default 1 set, device_dafault = %d\n", cdev);
acc_set_device_num(, acc_device_default);
cdev = acc_get_device_num(acc_device_nvidia);
printf("default 1 set, device_nvidia = %d\n", cdev);
acc_set_device_num(, acc_device_nvidia);
cdev = acc_get_device_num(acc_device_default);
printf(" nvidia 1 set, device_default = %d\n", cdev);
acc_set_device_num(, acc_device_nvidia);
cdev = acc_get_device_num(acc_device_nvidia);
printf(" nvidia 1 set, device_nvidia = %d\n", cdev);
num = acc_get_num_devices(acc_device_nvidia);
for(i = -num; i< *num; i++)
{
acc_set_device_num(i, acc_device_nvidia);
cdev = acc_get_device_num(acc_device_nvidia);
printf("i =%2d, cdev = %d\n",i, cdev);
}
return ;
}
编译信息