前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >请原谅我是个这么努力的单身狗,单线程已经无法表达我的爱!

请原谅我是个这么努力的单身狗,单线程已经无法表达我的爱!

作者头像
GPUS Lady
发布2018-04-02 10:46:17
9220
发布2018-04-02 10:46:17
举报
文章被收录于专栏:GPUS开发者

生活不止眼前的苟且,

还有套路与反套路的情人节!

今天是2017年的情人节,

在这样一场年度虐狗大会中,

如果还用鲜花巧克力的套路,

那就实在太无趣了!

就在Lady我在网络上发起用并行编程语言写一个爱的宣言,

单身狗们纷纷

无视我了!

直到昨天晚上,QQ群里终于站出一个人说:

我用OpenMP写总可以吧!

把代码贴在此:

#include <omp.h> #include <stdio.h>

int main () { long int NUMTHRD,i = 0; # ifdef _OPENMP printf("************************************"); printf("\n This is an OpenMP program for 2.14 "); printf("\n 2017.02.12 By 飞翔的蚂蚁 "); printf("\n************************************\n"); # endif printf("\nThe limit threads on this device is: %d threads !\nPlease input the number of parallel thread you want created:\n", omp_get_thread_limit()); AT: scanf("%d", &NUMTHRD); if(NUMTHRD > 20000) { printf("\aThe thread you set may cause application errors,\nplease reenter a little number no more big than 20000!!!\n"); goto AT; } omp_set_max_active_levels(8); omp_set_num_threads(NUMTHRD); printf("The number you set is %d,\nBefore parallel start test number of thread is %d !\nNow start parallel process...", NUMTHRD, omp_get_num_threads());

#pragma omp parallel { printf("\nFrom thread %d/%d said: I love you...", omp_get_thread_num(), omp_get_num_threads()); i ++ ; } #pragma omp barrier #pragma omp single { if(i != NUMTHRD) { printf("\a\a\n\nMay be you computer have be lazy..."); } printf("\a\nAll done, totally run in %d threads !",i); printf("\nThe max active level on this device is: %d level !", omp_get_max_active_levels()); } return 0; }

执行的结果:

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-02-14,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 GPUS开发者 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档