Source
stringlengths
36
77
Code Snippet
stringlengths
53
394
Question
stringclasses
1 value
Answer
stringlengths
54
406
https://www.psc.edu/wp-content/uploads/2022/01/Advanced-OpenMP.pdf
float array_sum(float *a, int length){ \n float total=0; \n for (int i = 0; i < length; i++) { \n total += a[i]; } \n return total; \n }
Please generate the optimized version of the given OpenMP code.
float array_sum(float *a, int length){ \n float total=0;\n #pragma omp parallel for reduction(+:total) \n for (int i = 0; i < length; i++) {\n total += a[i]; \n } \n return total; }
https://www.psc.edu/wp-content/uploads/2022/01/Advanced-OpenMP.pdf
float array_sum(float *a, int length){ \n // terminal case if (length == 0) {\n return 0;\n } \n else if (length == 1) { \n return a[0]; \n } // recursive case int half = length / 2; \n return array_sum(a, half) + sum(a + half, length - half); \n }
Please generate the optimized version of the given OpenMP code.
float array_sum(float *a, int length){\nif (length == 0) {\nreturn 0;\n}\nelse if (length == 1) {\nreturn a[0];\n}\nint half = length / 2;\nfloat x, y;\n#pragma omp parallel\n#pragma omp single nowait\n{\n#pragma omp task shared(x)\nx = array_sum(a, half);\n#pragma omp task shared(y)\ny = array_sum(a + half, length - half);\n#pragma omp taskwait\nx += y;\n}\nreturn x;\n}
https://www.codee.com/catalog/PWR001
#define N 100\nint A[N];\nint B[N];\n\nvoid init() {\n for (int i = 0; i < N; i++) {\n A[i] = i;\n }\n}\n\nvoid add() {\n for (int i = 0; i < N; i++) {\n B[i] = A[i] + 1;\n }\n}\n\nvoid foo() {\n init();\n add();\n}\n
Please generate the optimized version of the given OpenMP code.
#define N 100\nint A[N];\nint B[N];\n\nvoid init(int *A) {\n for (int i = 0; i < N; i++) {\n A[i] = i;\n }\n}\n\nvoid add(int *A, int*B) {\n for (int i = 0; i < N; i++) {\n B[i] = A[i] + 1;\n }\n}\n\nvoid foo() {\n init(A);\n add(A, B);\n}\n
https://www.codee.com/catalog/PWR046
float calc_div(float a, float b, float c) {\n return a / b / c;\n}\n
Please generate the optimized version of the given OpenMP code.
float calc_div(float a, float b, float c) {\n return a / (b * c);\n}\n
https://www.codee.com/catalog/PWR045
float calc_div_recip(float* out, float* in, int n, float b) {\n for (int i = 0; i < n; ++i) {\n out[i] = in[i] / b;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
float calc_div_recip(float* out, float* in, int n, float b) {\n float recip_b = 1.0f / b;\n for (int i = 0; i < n; ++i) {\n out[i] = in[i] * recip_b;\n }\n}\n
https://www.codee.com/catalog/PWR044
float calc_const(float a) {\n return a * 2.2;\n}\n
Please generate the optimized version of the given OpenMP code.
float calc_const(float a) {\n return a * 2.2f;\n}\n
https://www.codee.com/catalog/PWR043
for (int i = 0; i < n; i++) {\n double s = 0.0;\n for (int j = 0; j < n; j++) {\n s += a[j][i];\n }\n b[i] = s;\n}\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < n; i++) {\n b[i] = 0.0;\n for (int j = 0; j < n; j++) {\n b[i] += a[j][i];\n }\n}\n
https://www.codee.com/catalog/PWR042
for (int i = 0; i < n; i++) {\n double s = 0.0;\n for (int j = 0; j < n; j++) {\n s += A[j][i];\n }\n B[i] = 0.1 * s;\n }\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < n; i++) {\n s[i] = 0.0;\n for (int j = 0; j < n; j++) {\n s[i] += a[j][i];\n }\n b[i] = 0.1 * s[i];\n}\n
https://www.codee.com/catalog/PWR040
void copy(double **A, double **B, int n) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n A[i][j] = B[j][i];\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
for (int ii = 0; ii < n; ii+=TILE_SIZE) {\n for (int jj = 0; jj < n; jj+=TILE_SIZE) {\n for (int i = ii; i < MIN(ii + TILE_SIZE, n); i++) {\n for (int j = jj; j < MIN(jj + TILE_SIZE, n); j++) {\n A[i][j] = B[j][i];\n }\n }\n }\n}\n
https://www.codee.com/catalog/PWR039
void zero(double **A, int n) {\n for (int i = 0; i < n; i++) {\n for (int j = 0; j < n; j++) {\n A[j][i] = 0.0;\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void zero(double **A, int n) {\n for (int j = 0; j < n; j++) {\n for (int i = 0; i < n; i++) {\n A[j][i] = 0.0;\n }\n }\n
https://www.codee.com/catalog/PWR036
void example(float *a, unsigned *b, unsigned size) {\n for (unsigned i = 0; i < size; ++i) {\n a[b[i]] = 0.f;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < LEN_1D; ++i) {\n for (int j = 1; j < LEN_1D; j++) {\n c[i] += a[index[j]];\n }\n}\n
https://www.codee.com/catalog/PWR034
void example(float *a, unsigned size) {\n for (unsigned i = 0; i < size; i += 2) {\n a[i] = 0.f;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < LEN; ++i) {\n for (int j = 1; j < LEN; j++) {\n a[j * LEN + i] = a[j * LEN + i - 1] + b[j * LEN + i];\n }\n}\n
https://www.codee.com/catalog/PWR032
#include <math.h>\n\nvoid example(float x) {\n float res = sin(x);\n}\n
Please generate the optimized version of the given OpenMP code.
#include <math.h>\n\nvoid example(float x) {\n float res = sinf(x);\n}\n
https://www.codee.com/catalog/PWR030
for (int i = 0; i < size; i++) {\n for (int j = 0; j < size; j++) {\n float* a = aa[i];\n float* b = bb[0] + j;\n float* c = &cc[i][j];\n for (int k = 0; k < size; k++) { \n c[0] = c[0] + a[k] * b[0];\n b += size;\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < size; i++) {\n for (int j = 0; j < size; j++) {\n for (int k = 0; k < size; k++) { \n cc[i][j = cc[i][j] + aa[i][k] * b[k][j];\n }\n }\n}\n
https://www.codee.com/catalog/PWR007
ROGRAM p\n NUM1 = 7\n NUM2 = 2.5\n RES = NUM1/NUM2 ! RES = 3.0\nEND PROGRAM p\n
Please generate the optimized version of the given OpenMP code.
PROGRAM p\n IMPLICIT NONE\n INTEGER :: NUM1 = 7\n REAL :: NUM2 = 2.5, RES\n RES = NUM1/NUM2 ! RES = 2.799...\nEND PROGRAM p\n
https://www.codee.com/catalog/PWD011
double example(int m, double *A, double *B, double *C) {\n double liveOut;\n \n // liveOut is private but used after the loop, should be lastprivate\n#pragma omp parallel for private(liveOut)\n for (int i = 0; i < m; i++) {\n liveOut = A[i] * B[i];\n C[i] = C[i] + liveOut;\n }\n liveOut += 5;\n return liveOut;\n}\n
Please generate the optimized version of the given OpenMP code.
double example(int m, double *A, double *B, double *C) {\n double liveOut;\n \n // liveOut is private but used after the loop, should be lastprivate\n#pragma omp parallel for lastprivate(liveOut)\n for (int i = 0; i < m; i++) {\n liveOut = A[i] * B[i];\n C[i] = C[i] + liveOut;\n }\n liveOut += 5;\n return liveOut;\n}\n
https://www.codee.com/catalog/PWD010
void example(int **result, unsigned rows, unsigned cols) {\n int i, j;\n \n // j is implicitly shared and it should be private!\n#pragma omp parallel for shared(result)\n for (i = 0; i < rows; i++) {\n for (j = 0; j < cols; j++) {\n result[i][j] = 0;\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(int **result, unsigned rows, unsigned cols) {\n int i, j;\n \n // j is implicitly shared and it should be private!\n#pragma omp parallel for shared(result) private(j)\n for (i = 0; i < rows; i++) {\n for (j = 0; j < cols; j++) {\n result[i][j] = 0;\n }\n }\n}\n
https://www.codee.com/catalog/PWD008
void foo() {\n int A[5][5];\n \n #pragma omp parallel for\n for (int i = 1; i < 5; ++i) {\n for (int j = 0; j < 5; ++j) {\n A[i][j] += A[i][j-1];\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int A[5][5];\n \n #pragma omp parallel for\n for (int i = 1; i < 5; ++i) {\n for (int j = 1; j < 5; ++j) {\n A[i][j] += A[i][j-1];\n }\n }\n}
https://www.codee.com/catalog/PWD006
void foo(int **A) {\n #pragma omp target teams distribute parallel for map(tofrom:A)\n for (size_t i = 0; i < 10; i++) {\n A[i][i] += i;\n }\n}
Please generate the optimized version of the given OpenMP code.
void foo(int **A) {\n #pragma omp target teams distribute parallel for map(tofrom:A[0:10][0:10])\n for (size_t i = 0; i < 10; i++) {\n A[i][i] += i;\n }\n}
https://www.codee.com/catalog/PWD004
void foo() {\n int A[100];\n for (int i = 0; i < 100; i++) {\n A[i + 1] = 1;\n }\n}
Please generate the optimized version of the given OpenMP code.
void foo() {\n int A[100];\n for (int i = 0; i < 100; i++) {\n A[i] = 1;\n }\n}
https://www.codee.com/catalog/PWD002
void foo() {\n int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n int sum = 0;\n\n #pragma omp parallel for default(none) shared(array, sum)\n for (int i = 0; i < 10; i++) {\n sum += array[i];\n }\n}
Please generate the optimized version of the given OpenMP code.
void foo() {\n int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};\n int sum = 0;\n\n #pragma omp parallel for default(none) shared(array, sum)\n for (int i = 0; i < 10; i++) {\n #pragma omp atomic update\n sum += array[i];\n }\n}
https://www.codee.com/catalog/PWR057
void example(double *A, int *nodes1, int *nodes2, int *nodes3, int n) {\n for (int nel = 0; nel < n; ++nel) {\n A[nodes1[nel]] += nel * 1;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(double *A, int *nodes1, int *nodes2, int *nodes3, int n) {\n #pragma acc data copyin(n, nodes1[0:n]) copy(A[:])\n #pragma acc parallel\n #pragma acc loop\n for (int nel = 0; nel < n; ++nel) {\n #pragma acc atomic update\n A[nodes1[nel]] += nel * 1;\n }\n}\n
https://www.codee.com/catalog/PWR055
void example(double *D, double *X, double *Y, int n, double a) {\n for (int i = 0; i < n; ++i) {\n D[i] = a * X[i] + Y[i];\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(double *D, double *X, double *Y, int n, double a) {\n #pragma acc data copyin(X[0:n], Y[0:n], a, n) copyout(D[0:n])\n #pragma acc parallel\n #pragma acc loop\n for (int i = 0; i < n; ++i) {\n D[i] = a * X[i] + Y[i];\n }\n}\n
https://www.codee.com/catalog/PWR054
#include <stdio.h>\n\ndouble example(double *A, int n) {\n double sum = 0;\n for (int i = 0; i < n; ++i) {\n sum += A[i];\n }\n printf("%f", sum);\n return sum;\n}\n
Please generate the optimized version of the given OpenMP code.
#include <stdio.h>\n\ndouble example(double *A, int n) {\n double sum = 0;\n #pragma omp simd reduction(+: sum)\n for (int i = 0; i < n; ++i) {\n sum += A[i];\n }\n printf("%f", sum);\n return sum;\n}\n
https://www.codee.com/catalog/PWR052
void example(double *A, int *nodes1, int *nodes2, int *nodes3, int n) {\n for (int nel = 0; nel < n; ++nel) {\n A[nodes1[nel]] += nel * 1;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(double *A, int *nodes1, int *nodes2, int *nodes3, int n) {\n #pragma omp parallel default(none) shared(A, n, nodes1)\n {\n #pragma omp for schedule(auto)\n for (int nel = 0; nel < n; ++nel) {\n #pragma omp atomic update\n A[nodes1[nel]] += nel * 1;\n }\n } // end parallel\n}\n
https://www.codee.com/catalog/PWR051
#include <stdio.h>\n\ndouble example(double *A, int n) {\n double sum = 0;\n for (int i = 0; i < n; ++i) {\n sum += A[i];\n }\n printf("%f", sum);\n return sum;\n}\n
Please generate the optimized version of the given OpenMP code.
#include <stdio.h>\n\ndouble example(double *A, int n) {\n double sum = 0;\n #pragma omp parallel default(none) shared(A, n, sum)\n {\n #pragma omp for reduction(+: sum) schedule(auto)\n for (int i = 0; i < n; ++i) {\n sum += A[i];\n }\n } // end parallel\n printf("%f", sum);\n return sum;\n}\n
https://www.codee.com/catalog/PWR048
double calc_fma(double a, double b, double c) {\n return a + b * c;\n}\n
Please generate the optimized version of the given OpenMP code.
double calc_fma(double a, double b, double c) {\n return fma(b, c, a);\n}\n
https://www.codee.com/catalog/PWR029
void example(float *a, float *b, unsigned size) {\n unsigned k = 0;\n for (unsigned i = 0; i < size; i++) {\n b[i] = a[k] + 1;\n k = k + 1;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
for (unsigned i = 0; i < LEN_1D/2; i++) {\n b[i] = a[i] + 1;\n }\n\n
https://www.codee.com/catalog/PWR025
int foo(int a) { return 2 * a; }\n \nvoid example(int *A, int n) {\n for (int i = 0; i < n; i++) {\n A[i] = foo(i);\n }\n}\n
Please generate the optimized version of the given OpenMP code.
#pragma omp declare simd\nint foo(int a) { return 2 * a; }\n \nvoid example(int *A, int n) {\n for (int i = 0; i < n; i++) {\n A[i] = foo(i);\n }\n}\n
https://www.codee.com/catalog/PWR023
int example(int *x, int *y) {\n int sum = 0;\n for (int i = 0; i < 10; ++i) {\n sum += x[i];\n y[i] = 2;\n }\n return sum;\n}\n
Please generate the optimized version of the given OpenMP code.
int example(int* restrict x, int* restrict y) {\n int sum = 0;\n for (int i = 0; i < 10; ++i) {\n sum += x[i];\n y[i] = 2;\n }\n return sum;\n}\n
https://www.codee.com/catalog/PWR021
int expensive_computation(int *C, int i) { return C[i] * 2; }\n \nvoid example(int *A, int *C) {\n for (int i = 0; i < 1000; i++) {\n int t = expensive_computation(C, i);\n A[C[i]] = t;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
int expensive_computation(int *C, int i) { return C[i] * 2; }\n \nvoid example(int *A, int *C) {\n int t[1000];\n for (int i = 0; i < 1000; i++) {\n t[i] = expensive_computation(C, i);\n }\n \n for (int i = 0; i < 1000; i++) {\n A[C[i]] = t[i];\n }\n}\n
https://www.codee.com/catalog/PWR020
void example() {\n int A[1000], B[1000], C[1000];\n\n for (int i = 0; i < 1000; i++) {\n A[i] = B[i] = C[i] = i;\n }\n\n for (int i = 0; i < 1000; i++) {\n A[i] += i;\n B[C[i]] += i;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example() {\n int A[1000], B[1000], C[1000];\n\n for (int i = 0; i < 1000; i++) {\n A[i] = B[i] = C[i] = i;\n }\n\n for (int i = 0; i < 1000; i++) {\n A[i] += i;\n }\n\n for (int i = 0; i < 1000; i++) {\n B[C[i]] += i;\n }\n}\n\n
https://www.codee.com/catalog/PWR018
double fib(unsigned n) {\n if (n == 0) {\n return 0.;\n }\n if (n == 1) {\n return 1.;\n }\n return fib(n - 1) + fib(n - 2);\n}\n\nint example(unsigned times) {\n double sum = 0.;\n for (unsigned i = 0; i < times; i++) {\n sum += fib(i);\n }\n return sum;\n}\n
Please generate the optimized version of the given OpenMP code.
int example(unsigned times) {\n double sum = 0.0;\n double fib_0 = 0.0;\n double fib_1 = 1.0;\n for (unsigned i = 2; i < times; i++) {\n double fib = fib_0 + fib_1;\n sum += fib;\n fib_0 = fib_1;\n fib_1 = fib;\n }\n}\n
https://www.codee.com/catalog/PWR016
typedef struct {\n int x;\n int y;\n int z;\n} point;\n \nvoid foo() {\n point points[1000];\n for (int i = 0; i < 1000; i ++) {\n points[i].x = 1;\n points[i].y = 1;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int points_x[1000];\n int points_y[1000];\n int points_z[1000];\n for (int i = 0; i < 1000; i ++) {\n points_x[i] = 1;\n points_y[i] = 1;\n }\n}\n
https://www.codee.com/catalog/PWR014
void foo() {\n int A[100][100];\n for (int i = 1; i < 100; ++i) {\n for (int j = 0; j < 100; ++j) {\n A[i][j-1] = 1;\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int A[100][100];\n for (int i = 1; i < 100; ++i) {\n for (int j = 0; j < 99; ++j) {\n A[i][j] = 1;\n }\n }\n}\n
https://www.codee.com/catalog/PWR012
#include <stdlib.h>\n \ntypedef struct\n{\n int A[1000];\n int B[1000];\n} data;\n \nint foo(data *d)\n{\n int result = 0;\n for (int i = 0; i < 1000; i++)\n {\n result += d->A[i];\n }\n return result;\n}\n \nvoid bar()\n{\n data *d = (data *)malloc(sizeof(data));\n for (int i = 0; i < 1000; i++)\n {\n d->A[i] = d->B[i] = 1;\n }\n int result = foo(d);\n}\n
Please generate the optimized version of the given OpenMP code.
#include <stdlib.h>\n \ntypedef struct\n{\n int A[1000];\n int B[1000];\n} data;\n \nint foo(int *A)\n{\n int result = 0;\n for (int i = 0; i < 1000; i++)\n {\n result += A[i];\n }\n return result;\n}\n \nvoid bar()\n{\n data *d = (data *)malloc(sizeof(data));\n for (int i = 0; i < 1000; i++)\n {\n d->A[i] = d->B[i] = 1;\n }\n int result = foo(d->A);\n free(d);\n}\n
https://www.codee.com/catalog/PWR010
for (int j = 0; j < n; ++j) {\n for (int i = 0; i < n; ++i) {\n A[i][j] = 0;\n }\n }\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < n; ++i) {\n for (int j = 0; j < n; ++j) {\n A[i][j] = 0;\n }\n }\n
https://www.codee.com/catalog/PWR006
#define SIZE 5\n\nvoid foo() {\n int A[SIZE] = {1, 2, 3, 4, 5};\n int B[SIZE] = {5, 4, 3, 2, 1};\n int sum[SIZE];\n\n #pragma omp parallel for shared(sum) firstprivate(A, B)\n for (int i = 0; i < SIZE; i++) {\n sum[i] = A[i] + B[i];\n }\n}\n
Please generate the optimized version of the given OpenMP code.
#define SIZE 5\n\nvoid foo() {\n int A[SIZE] = {1, 2, 3, 4, 5};\n int B[SIZE] = {5, 4, 3, 2, 1};\n int sum[SIZE];\n\n #pragma omp parallel for shared(sum, A, B)\n for (int i = 0; i < SIZE; i++) {\n sum[i] = A[i] + B[i];\n }\n}\n
https://www.codee.com/catalog/PWR004
void foo() {\n int factor = 42;\n int result[10];\n\n #pragma omp parallel for\n for (int i = 0; i < 10; i++) {\n result[i] = factor * i;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int factor = 42;\n int result[10];\n\n #pragma omp parallel for shared(result, factor)\n for (int i = 0; i < 10; i++) {\n result[i] = factor * i;\n }\n}\n
https://www.codee.com/catalog/PWR015
void foo() {\n int A[100], B[100], sum[100];\n #pragma omp target map(to: A[0:100], B[0:100]) map(from: sum[0:100])\n #pragma omp parallel for\n for (int i = 0; i < 50; i++) {\n sum[i] = A[i] + B[i];\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int A[100], B[100], sum[100];\n #pragma omp target map(to: A[0:50], B[0:50]) map(from: sum[0:50])\n #pragma omp parallel for\n for (int i = 0; i < 50; i++) {\n sum[i] = A[i] + B[i];\n }\n}\n
https://www.codee.com/catalog/PWR017
while (i < n) {\n b[i] = a[i];\n i++;\n}\nint example(int *A) {\n int sum = 0;\n int i = 0;\n while (i < 1000) {\n sum += A[i++];\n }\n return sum;\n}\n
Please generate the optimized version of the given OpenMP code.
int sum = 0;\nfor (int i = 0; i < 1000; i++) {\n sum += A[i];\n}\n
https://www.codee.com/catalog/PWR019
for (int i = 0; i < n; i++) {\n for (int j = margin; j < n - margin; j++) {\n bb[i][j] = 0.0;\n for (int k = -margin; k < margin; k++) {\n bb[i][j] += aa[i][j + k];\n }\n }\n}\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < n; i++) {\n for (int j = margin; j < n - margin; j++) {\n bb[i][j] = 0.0;\n }\n\n for (int k = -margin; k < margin; k++) {\n for (int j = margin; j < LEN_2D - margin; j++) {\n bb[i][j] += aa[i][j + k];\n }\n }\n}\n
https://www.codee.com/catalog/PWR009
#pragma omp target map(to: A[0:m][0:p], B[0:p][0:n], m, n, p) map(tofrom: C[0:m][0:n])\n{\n#pragma omp parallel default(none) shared(A, B, C, m, n, p)\n{\n#pragma omp for schedule(auto)\nfor (size_t i = 0; i < m; i++) {\n for (size_t j = 0; j < n; j++) {\n for (size_t k = 0; k < p; k++) {\n C[i][j] += A[i][k] * B[k][j];\n }\n }\n}\n} // end parallel\n} // end target\n
Please generate the optimized version of the given OpenMP code.
#pragma omp target teams distribute parallel for map(to: A[0:m][0:p], B[0:p][0:n], m, n, p) shared(A, B, m, n, p) map(tofrom: C[0:m][0:n]) schedule(auto)\nfor (size_t i = 0; i < m; i++) {\n for (size_t j = 0; j < n; j++) {\n for (size_t k = 0; k < p; k++) {\n C[i][j] += A[i][k] * B[k][j];\n }\n }\n}\n
https://www.codee.com/catalog/PWR024
int example(int **A, int n, int m) {\n int i = 0;\n for (; i < n; i++) {\n A[i] = m;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
int example(int **A, int n, int m) {\n int i;\n for (i = 0; i < n; i++) {\n A[i] = m;\n }\n}\n\n
https://www.codee.com/catalog/PWR028
void example(float *a, float *b, float *c, unsigned size, unsigned inc) {\n float *bTemp1 = b;\n for (unsigned i = 0; i < size; i++) {\n c[0] += (a[i] * bTemp1[0]);\n bTemp1 -= inc;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(float *a, float *b, float *c, unsigned size, unsigned inc) {\n for (unsigned i = 0; i < size; i++) {\n c[0] += (a[i] * bTemp1[-i * inc]);\n }\n}\n
https://www.codee.com/catalog/PWR050
void example(double *D, double *X, double *Y, int n, double a) {\n for (int i = 0; i < n; ++i) {\n D[i] = a * X[i] + Y[i];\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(double *D, double *X, double *Y, int n, double a) {\n #pragma omp parallel default(none) shared(D, X, Y, a, n)\n {\n #pragma omp for schedule(auto)\n for (int i = 0; i < n; ++i) {\n D[i] = a * X[i] + Y[i];\n }\n } // end parallel\n}\n
https://www.codee.com/catalog/PWR056
#include <stdio.h>\n\ndouble example(double *A, int n) {\n double sum = 0;\n for (int i = 0; i < n; ++i) {\n sum += A[i];\n }\n printf("%f", sum);\n return sum;\n}\n
Please generate the optimized version of the given OpenMP code.
#pragma acc data copyin(A[0:n], n) copy(sum)\n#pragma acc parallel\n#pragma acc loop reduction(+: sum)\nfor (int i = 0; i < n; ++i) {\n sum += A[i];\n}\n
https://www.codee.com/catalog/PWD003
void foo(int* a, int* b, int* sum, int size) {\n #pragma omp target map(to: a, b) map(from: sum)\n #pragma omp parallel for\n for (int i = 0; i < size; i++) {\n sum[i] = a[i] + b[i];\n }\n}
Please generate the optimized version of the given OpenMP code.
void foo(int* a, int* b, int* sum, int size) {\n #pragma omp target map(to: a[0:size], b[0:size]) map(from: sum[0:size])\n #pragma omp parallel for\n for (int i = 0; i < size; i++) {\n sum[i] = a[i] + b[i];\n }\n}
https://www.codee.com/catalog/PWD007
void foo() {\n int x[10], y[10];\n \n y[0] = 0;\n #pragma omp parallel for\n for (int i=1; i<10; i++) {\n y[i] = y[i-1] + x[i-1];\n }\n}
Please generate the optimized version of the given OpenMP code.
void foo() {\n int x[10], y[10];\n \n int scan_x = 0;\n #pragma omp parallel for reduction(inscan, +:scan_x)\n for (int i=0; i<10; i++) {\n y[i] = scan_x;\n #pragma omp scan exclusive(scan_x)\n scan_x += x[i];\n }\n}
https://www.codee.com/catalog/PWD009
void example(int m, double *A, double *B, double *C) {\n double temp;\n \n#pragma omp parallel for default(none) private(temp, C) shared(A, B, m)\n for (int i = 0; i < m; i++) {\n temp = A[i] * B[i];\n C[i] = C[i] + temp;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(int m, double *A, double *B, double *C) {\n double temp;\n \n#pragma omp parallel for default(none) private(temp) shared(A, B, C, m)\n for (int i = 0; i < m; i++) {\n temp = A[i] * B[i];\n C[i] = C[i] + temp;\n }\n}\n
https://www.codee.com/catalog/PWR008
PROGRAM p\n IMPLICIT NONE\n INTEGER :: s = 2\n CALL f(s, 2)\nCONTAINS\n SUBROUTINE f(a, b)\n IMPLICIT NONE\n INTEGER :: a\n INTEGER :: b\n a = 5\n b = a * 2\n END SUBROUTINE f\nEND PROGRAM\n
Please generate the optimized version of the given OpenMP code.
PROGRAM p\n IMPLICIT NONE\n INTEGER :: s = 2\n CALL f(s, 2)\nCONTAINS\n SUBROUTINE f(a, b)\n IMPLICIT NONE\n INTEGER, INTENT(IN) :: a\n INTEGER, INTENT(OUT) :: b\n a = 5\n b = a * 2\n END SUBROUTINE f\nEND PROGRAM\n
https://www.codee.com/catalog/PWR033
void example(int addTwo) {\n int sum = 0;\n for (int i = 0; i < 1000; i++) {\n sum += addTwo ? 2 : 1;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void example(int addTwo) {\n int sum = 0;\n int add = addTwo ? 2 : 1\n for (int i = 0; i < 1000; i++) {\n sum += add;\n }\n}\n
https://www.codee.com/catalog/PWR060
for (int i = 0; i < n; ++i) {\n D[i] = a * X[index[i]] + Y[i]\n}\n
Please generate the optimized version of the given OpenMP code.
for (int i = 0; i < n; ++i) {\n X_index_i[i] = X[index[i]];\n}\nfor (int i = 0; i < n; ++i) {\n D[i] = a * X_index_i[i] + Y[i]\n}\n
https://www.codee.com/catalog/PWR002
void foo() {\n int t;\n int result[10];\n\n for (int i = 0; i < 10; i++) {\n t = i + 1;\n result[i] = t;\n }\n}\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int result[10];\n\n for (int i = 0; i < 10; i++) {\n int t = i + 1;\n result[i] = t;\n }\n}\n
https://www.codee.com/catalog/PWR005
void foo() {\n int t;\n int result[10];\n\n #pragma omp parallel for\n for (int i = 0; i < 10; i++) {\n t = i + 1;\n result[i] = t;\n }\n}\n\n
Please generate the optimized version of the given OpenMP code.
void foo() {\n int t;\n int result[10];\n\n #pragma omp parallel for default(none)\n for (int i = 0; i < 10; i++) {\n t = i + 1;\n result[i] = t;\n }\n}\n\n
https://www.codee.com/catalog/PWR022
int example(int *A, int n) {\n int total = 0;\n for (int i = 0; i < n; i++) {\n if (n < 10) {\n total++;\n }\n A[i] = total;\n }\n return total;\n}\n
Please generate the optimized version of the given OpenMP code.
int example(int *A, int n) {\n int total = 0;\n if (n < 10) {\n for (int i = 0; i < n; i++) {\n total++;\n A[i] = total;\n }\n } else {\n for (int i = 0; i < n; i++) {\n A[i] = total;\n }\n }\n return total;\n}\n
https://www.codee.com/catalog/PWR031
#include <math.h>\n\nfloat example(float *a, float x) {\n for (int i = 0; i < 10; ++i) {\n a[i] = pow(x, 1.5);\n }\n}\n
Please generate the optimized version of the given OpenMP code.
#include <math.h>\n\nfloat example(float *a, float x) {\n for (int i = 0; i < 10; ++i) {\n a[i] = x * sqrt(x);\n }\n}\n
http://akira.ruc.dk/~keld/teaching/IPDC_f10/Slides/pdf4x/4_Performance.4x.pdf
#pragma omp parallel for \n for (.....) { /*-- Work-sharing loop 1 --*/ } \n #pragma omp parallel for \n for (....) { /*-- Work-sharing loop 2 --*/ } \n #pragma omp parallel for \n for (.....) \n { /*-- Work-sharing loop N --*/ }
Please generate the optimized version of the given OpenMP code.
#pragma omp parallel \n { \n #pragma omp for \n /*-- Work-sharing loop 1 --*/ {...... } \n #pragma omp for \n /*-- Work-sharing loop 2 --*/ {...... } #pragma omp for \n /*-- Work-sharing loop N --*/ { ...... }}
http://akira.ruc.dk/~keld/teaching/IPDC_f10/Slides/pdf4x/4_Performance.4x.pdf
for (i=0; i<n; i++) \n for (j=0; j<n; j++) \n #pragma omp parallel for \n for (k=0; k<n; k++) { \n ... \n}
Please generate the optimized version of the given OpenMP code.
#pragma omp parallel \n for (i=0; i<n; i++) \n for (j=0; j<n; j++) \n #pragma omp for \n for (k=0; k<n; k++) {\n .....\n }
http://akira.ruc.dk/~keld/teaching/IPDC_f10/Slides/pdf4x/4_Performance.4x.pdf
for (int i=0; i<n; i++) { \n c[i] = exp(i/n); \n for (int j=0; j<m; j++) \n a[j][i] = b[j][i] + d[j] * e[i];}
Please generate the optimized version of the given OpenMP code.
for (int i=0; i<n; i++) \n c[i] = exp(i/n); \n for (int j=0; j<m; j++) \n for (int i=0; i<n; i++) \n a[j][i] = b[j][i] + d[j]* e[i];
http://akira.ruc.dk/~keld/teaching/IPDC_f10/Slides/pdf4x/4_Performance.4x.pdf
for (int i=0; i<n; i++) \n a[i] = b[i] * 2; \n for (int i=0; i<n; i++) \n { x[i] = 2 * x[i]; \n c[i] = a[i] + 2; \n }
Please generate the optimized version of the given OpenMP code.
for (int i=0; i<n; i++) {\n a[i]= b[i] *2; \n c[i]=a[i] + 2; \n x[i]= 2 *x[i]; \n}
http://akira.ruc.dk/~keld/teaching/IPDC_f10/Slides/pdf4x/4_Performance.4x.pdf
for (int i=0; i<n; i++) \n for (int j=0; j<m; j++) \n b[i][j] = a[j] [i];
Please generate the optimized version of the given OpenMP code.
for (int j1=0; j1<n; j1+=nbj) \n for (int i=0; i<n; i++) \n for (int j2=0; j2<MIN(n-j1,nbj); j2++) \n b[i][j1+j2] = a[j1+j2][i];
http://akira.ruc.dk/~keld/teaching/IPDC_f10/Slides/pdf4x/4_Performance.4x.pdf
for (int i=1; i<n; i++) {\n a[i] = b[i] + 1; \n c[i] = a[i] +a[i-1] + b[i-1];}
Please generate the optimized version of the given OpenMP code.
for (int i=1; i<n; i+=2) { \n a[i] = b[i] + 1; \n c[i] = a[i] + a[i-1] + b[i-1]; \n a[i+1] = b[i+1] + 1; \n c[i+1] = a[i+1] + a[i] + b[i]; }