Created
February 18, 2016 10:16
-
-
Save pkulev/dd514af44697a34be8cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int pow2(int val) | |
{ | |
return val * val; | |
} | |
int* map(int (*func)(int), int *arr, int len) | |
{ | |
int *res = malloc(sizeof(int) * len); | |
for (int i = 0; i < len; i++) { | |
res[i] = func(arr[i]); | |
} | |
return res; | |
} | |
int main(void) | |
{ | |
int len = 10; | |
int arr[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | |
int *powered2; | |
#pragma omp parallel | |
powered2 = map(pow2, arr, len); | |
#pragma omp parallel for | |
for (int i = 0; i < len; i++) { | |
printf("Original: %d, powered: %d\n", arr[i], powered2[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment