getnumdevices.c && setgetdevicetype例程

本文展示了如何使用OpenACC库中的acc_get_num_devices()和acc_set_device_type()函数来测试设备数量与设备类型设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

getnumdevices.c代码

 1 /* 文件名: getnumdevices.c
 2 * 功能 : 测试函数acc_get_num_devices(.)
 3 */
 4 #include<stdio.h>
 5 #include "openacc.h"
 6 int main()
 7 {
 8 int num = -8888;
 9 num = acc_get_num_devices(acc_device_none);
10 printf("device_non = %d\n", num);
11 num = acc_get_num_devices(acc_device_default);
12 printf("device_deault = %d\n", num);
13 num = acc_get_num_devices(acc_device_host);
14 printf("device_host = %d\n", num);
15 num = acc_get_num_devices(acc_device_not_host);
16 printf("device_not_host = %d\n", num);
17 num = acc_get_num_devices(acc_device_nvidia);
18 printf("device_nvidia = %d\n", num);
19 return 0;
20 }

 

setgetdevicetype.c代码

 1 /* 文件名: setgetdevicetype.c
 2 * 功能 : 测试两个函数acc_set_device_type(.)和acc_get_device_type(.).
 3 */
 4 #include<stdio.h>
 5 #include"openacc.h"
 6 int main()
 7 {
 8 acc_device_t devt = acc_device_none;
 9 devt = acc_get_device_type();
10 printf(" no device set, type = %d\n", devt);
11 acc_set_device_type(acc_device_default);
12 devt = acc_get_device_type();
13 printf(" device_default set, type = %d\n", devt);
14 acc_set_device_type(acc_device_nvidia);
15 devt = acc_get_device_type();
16 printf(" device_nvidia set, type = %d\n", devt);
17 acc_set_device_type(acc_device_host);
18 devt = acc_get_device_type();
19 printf(" device_host set, type = %d\n", devt);
20 acc_set_device_type(acc_device_not_host);
21 devt = acc_get_device_type();
22 printf("device_not_host set, type = %d\n", devt);
23 acc_set_device_type(acc_device_xeonphi);
24 devt = acc_get_device_type();
25 printf(" device_xeonphi set, type = %d\n", devt);
26 return 0;
27 }

编译信息:

转载于:https://www.cnblogs.com/liangliangdetianxia/p/4359931.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值