#include #include #ifdef _OPENMP #include #endif #ifdef LIKWID_PERFMON #include #else #define LIKWID_MARKER_INIT #define LIKWID_MARKER_REGISTER(regionTag) #define LIKWID_MARKER_START(regionTag) #define LIKWID_MARKER_STOP(regionTag) #define LIKWID_MARKER_CLOSE #endif int main(int argc, char *argv[]) { const int size = 1000; double *a = malloc(size * sizeof(double)); double *b = malloc(size * sizeof(double)); double *sum = malloc(size * sizeof(double)); double *prod = malloc(size * sizeof(double)); LIKWID_MARKER_INIT; #pragma omp parallel { LIKWID_MARKER_REGISTER("sum"); LIKWID_MARKER_REGISTER("prod"); #pragma omp barrier #pragma omp for for (int i = 0; i < size; i++) { a[i] = (double)(i + 1); b[i] = a[i]; } LIKWID_MARKER_START("sum"); #pragma omp for for (int i = 0; i < size; i++) { sum[i] = a[i] + b[i]; } LIKWID_MARKER_STOP("sum"); LIKWID_MARKER_START("prod"); #pragma omp for for (int i = 0; i < size; i++) { prod[i] = a[i] * b[i]; } LIKWID_MARKER_STOP("prod"); } printf(" Sum: first = %lf - last = %lf\n", sum[0], sum[size-1]); printf(" Product: first = %lf - last = %lf\n", prod[0], prod[size-1]); LIKWID_MARKER_CLOSE; free(a); free(b); free(sum); free(prod); return 0; }