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

2018-04-02 10:46:17 浏览数 (1)

生活不止眼前的苟且,

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

今天是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("aannMay be you computer have be lazy..."); } printf("anAll 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; }

执行的结果:

0 人点赞