1、 高性能计算实验报告学生姓名: X X 学 号: XXXXXXXXXX 班 号: 116122 指导教师: 郭明强 中国地质大学(武汉)信息工程学院第一题1.编写 console 程序2.由下图看出,电脑是双核 CPU3.多线程程序,利用 windowsAPI 函数创建线程代码#include “stdafx.h“#include#include “windows.h“using namespace std;DWORD WINAPI first(PVOID pParam)for (int i = 0;i using namespace std;/计算 eDWORD WINAPI ThreadC
2、alc_E(PVOID pParam)/计算 e子函数double factorial = 1;int i = 1;double e = 1;for (;i using namespace std;void main()#pragma omp parallel num_threads(8)printf(“Hello, World!, ThreadId=%dn“, omp_get_thread_num();2.For 语句#include “stdafx.h“#include “windows.h“#include “omp.h“#include using namespace std;void
3、 main()int j = 0;#pragma omp parallel#pragma omp forfor (j = 0;j using namespace std;void main(int argc, char * argv)#pragma omp parallel sections #pragma omp sectionprintf(“ section 1 threadid = %d n“, omp_get_thread_num();#pragma omp sectionprintf(“ section 2 threadid = %d n“, omp_get_thread_num()
4、;#pragma omp sectionprintf(“ section 3 threadid = %d n“, omp_get_thread_num();#pragma omp sectionprintf(“ section 4 threadid = %d n“, omp_get_thread_num();4.Threadprivate 语句的用法#include “stdafx.h“#include “windows.h“#include “omp.h“#include using namespace std;int a, b, i, tid;float x;#pragma omp thr
5、eadprivate(a,x)void main()/关闭动态线程分配omp_set_dynamic(0);printf(“1st Parallel Region:n“);#pragma omp parallel private(b,tid)tid = omp_get_thread_num();a = tid;b = tid;x = 1.1*tid + 1.0;printf(“Threading %d: a,b,x = %d %d %fn“, tid, a, b, x);/end of parallel sectionprintf(“*n“);printf(“主线程中串行线程n“);print
6、f(“*n“);printf(“2nd Parallel Region:n“);#pragma omp parallel private(tid)tid = omp_get_thread_num();printf(“Threading %d: a,b,x = %d %d %fn“, tid, a, b, x);/end of parallel section5.reduction 语句的用法#include “stdafx.h“#include “windows.h“#include “omp.h“#include using namespace std;#include void main() int i, n, chunk;float a100, b100, result;/变量的初始化n = 100;chunk = 10;result = 0.0;for (i = 0;i #define num_steps 20000000int main(int argc, char *argv)double start, stop;double e, pi, factorial, product;int i;/启动定时器start = clock();