?? ompi.c
字號:
#include <limits.h>
#include <stdio.h>
#include <omp.h>
#include <time.h>
static long num_steps = 1000000000;
double step, pi;
int main(int argc, char **argv)
{
int i;
double x, sum = 0.0;
clock_t t1, t2;
#pragma omp parallel
{
printf("Hello, I am OpenMP!\n");
}
step = 1.0 / (double)num_steps;
t1 = clock();
#pragma omp parallel for reduction(+: x, sum)
for (i = 0; i < num_steps; i++)
{
x = (i + 0.5) * step;
sum = sum + 4.0 / (1.0 + x * x);
}
t2 = clock();
pi = step * sum;
printf("Pi = %f, %.3f seconds", pi, (double)(t2 - t1) / CLOCKS_PER_SEC);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -