-
Notifications
You must be signed in to change notification settings - Fork 0
/
openmp5.c
69 lines (57 loc) · 1.46 KB
/
openmp5.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2014 UFSM, UNIPAMPA.
*
* Authors: Joao Lima (UFSM) and Claudio Schepke (Unipampa).
*/
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#define MAX_N 20000000
int main(void)
{
int N = MAX_N;
double t0, t1, tdelta;
int *a, *b;
int i;
a = (int*)calloc(MAX_N, sizeof(int));
b = (int*)calloc(MAX_N, sizeof(int));
/* zera valores e cria uma regiao paralela */
#pragma omp parallel
#pragma omp for
for(i = 0; i < N; i++)
a[i] = b[i] = 1;
/* teste com static */
t0 = omp_get_wtime();
#pragma omp parallel
#pragma omp for schedule(static)
for(i = 0; i < N; i++)
a[i] = a[i] + b[i];
t1 = omp_get_wtime();
tdelta = t1 - t0;
printf("Soma de %d numeros e schedule(static) em tempo: %.4f segundos.\n", N, tdelta);
/* zera valores */
for(i = 0; i < N; i++)
a[i] = b[i] = 1;
/* teste com dynamic */
t0 = omp_get_wtime();
#pragma omp parallel
#pragma omp for schedule(dynamic)
for(i = 0; i < N; i++)
a[i] = a[i] + b[i];
t1 = omp_get_wtime();
tdelta = t1 - t0;
printf("Soma de %d numeros e schedule(dynamic) em tempo: %.4f segundos.\n", N, tdelta);
/* zera valores */
for(i = 0; i < N; i++)
a[i] = b[i] = 1;
/* teste com auto */
t0 = omp_get_wtime();
#pragma omp parallel
#pragma omp for schedule(auto)
for(i = 0; i < N; i++)
a[i] = a[i] + b[i];
t1 = omp_get_wtime();
tdelta = t1 - t0;
printf("Soma de %d numeros e schedule(auto) em tempo: %.4f segundos.\n", N, tdelta);
return 0;
}