Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Gep print function and cilk examples
- Loading branch information
1 parent
1925ec6
commit b06b891
Showing
17 changed files
with
224 additions
and
464 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
#include <stdio.h> | ||
#include <cilk/cilk.h> | ||
|
||
void cilk_for_test02_mul(unsigned *a, unsigned *b, unsigned i) { | ||
b[i] = a[i]*2; | ||
return; | ||
} | ||
|
||
void cilk_for_test02(unsigned *a, unsigned *b) { | ||
unsigned cilk_for_test02(unsigned j) { | ||
unsigned foo = j; | ||
cilk_for (unsigned i = 0; i < 5; ++i) { | ||
cilk_for_test02_mul(a,b,i); | ||
cilk_for(unsigned k = 0; k < 5; ++k){ | ||
foo++; | ||
} | ||
} | ||
return; | ||
return foo; | ||
} | ||
|
||
int main() { | ||
int i; | ||
unsigned a[5] = {1,2,3,4,5}; | ||
unsigned b[5] = {0}; | ||
cilk_for_test02(a,b); | ||
for(i=0;i<5;i++) { | ||
printf("b[%d]=%d\n", i, b[i]); | ||
} | ||
|
||
int result = cilk_for_test02(100); | ||
printf("%d\n",result); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
#include <stdio.h> | ||
#include <cilk/cilk.h> | ||
|
||
unsigned cilk_for_test03(unsigned j) { | ||
unsigned foo = j; | ||
unsigned cilk_for_test03(unsigned *a, unsigned *b, unsigned *c) { | ||
cilk_for (unsigned i = 0; i < 5; ++i) { | ||
cilk_for(unsigned k = 0; k < 5; ++k){ | ||
foo++; | ||
} | ||
c[i]=a[i]+b[i]; | ||
} | ||
return foo; | ||
return 1; | ||
} | ||
|
||
int main() { | ||
int result = cilk_for_test03(100); | ||
printf("%d\n",result); | ||
int i; | ||
unsigned a[5] = {1,2,3,4,5}; | ||
unsigned b[5] = {1,2,3,4,5}; | ||
unsigned c[5] = {0}; | ||
cilk_for_test03(a,b,c); | ||
for(i=0;i<5;i++) { | ||
printf("%d\n", c[i]); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
#include <stdio.h> | ||
#include <cilk/cilk.h> | ||
#include <stdio.h> | ||
|
||
unsigned cilk_for_test04(unsigned *a, unsigned *b, unsigned *c) { | ||
cilk_for (unsigned i = 0; i < 5; ++i) { | ||
c[i]=a[i]+b[i]; | ||
cilk_for(unsigned i = 0; i < 20; ++i) { | ||
if (a[i] > b[i]) { | ||
c[i] = a[i] - b[i]; | ||
} else { | ||
c[i] = b[i] - a[i]; | ||
} | ||
} | ||
return 1; | ||
} | ||
|
||
int main() { | ||
int i; | ||
unsigned a[5] = {1,2,3,4,5}; | ||
unsigned b[5] = {1,2,3,4,5}; | ||
unsigned c[5] = {0}; | ||
cilk_for_test04(a,b,c); | ||
for(i=0;i<5;i++) { | ||
unsigned a[20] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | ||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; | ||
unsigned b[20] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19, | ||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
unsigned c[20] = {0}; | ||
cilk_for_test04(a, b, c); | ||
for (i = 0; i < 20; i++) { | ||
printf("%d\n", c[i]); | ||
} | ||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,80 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
#include <cilk/cilk.h> | ||
#include <cilk/cilk_api.h> | ||
|
||
unsigned cilk_for_test05(unsigned *a, unsigned *b, unsigned *c) { | ||
cilk_for (unsigned i = 0; i < 20; ++i) { | ||
if (a[i] > b[i]) { | ||
c[i]=a[i]-b[i]; | ||
} else { | ||
c[i]=b[i]-a[i]; | ||
} | ||
#define LOOP_SIZE 1000000 | ||
#define TIME | ||
|
||
double timespec_to_ms(struct timespec *ts) | ||
{ | ||
return ts->tv_sec*1000.0 + ts->tv_nsec/1000000.0; | ||
} | ||
|
||
|
||
int cilk_for_test05(int a[][5], int b[][5], int c[][5]) { | ||
cilk_for (int i = 0; i < 5; ++i) { | ||
cilk_for (int j = 0; j < 5; ++j) { | ||
c[i][j]=a[i][j]+b[i][j]; | ||
} | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
int main() { | ||
int i; | ||
unsigned a[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | ||
10,11,12,13,14,15,16,17,18,19}; | ||
unsigned b[20] = {10,11,12,13,14,15,16,17,18,19, | ||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
unsigned c[20] = {0}; | ||
cilk_for_test05(a,b,c); | ||
for(i=0;i<20;i++) { | ||
printf("%d\n", c[i]); | ||
int main(int argc, char *argv[]) { | ||
int i,j; | ||
int a[5][5] = {{ 1, 2, 3, 4, 5}, | ||
{11,12,13,14,15}, | ||
{21,22,23,24,25}, | ||
{31,32,33,34,35}, | ||
{41,42,43,44,45}}; | ||
int b[5][5] = {{ 1, 2, 3, 4, 5}, | ||
{11,12,13,14,15}, | ||
{21,22,23,24,25}, | ||
{31,32,33,34,35}, | ||
{41,42,43,44,45}}; | ||
int c[5][5] = {0}; | ||
// If we've got a parameter, assume it's the number of workers to be used | ||
if (argc > 1) | ||
{ | ||
// Values less than 1, or parameters that aren't numbers aren't allowed | ||
if (atoi(argv[1]) < 1) | ||
{ | ||
printf("Usage: fib [workers]\n"); | ||
return 1; | ||
} | ||
|
||
// Set the number of workers to be used | ||
#ifdef TIME | ||
__cilkrts_set_param("nworkers", argv[1]); | ||
#endif | ||
} | ||
|
||
// Time how long it takes | ||
#ifdef TIME | ||
struct timespec start_time, end_time; | ||
clock_gettime(CLOCK_MONOTONIC, &start_time); | ||
#endif | ||
|
||
for (int i=0;i<LOOP_SIZE;i++) { | ||
cilk_for_test05(a,b,c); | ||
} | ||
|
||
} | ||
#ifdef TIME | ||
clock_gettime(CLOCK_MONOTONIC, &end_time); | ||
double time_ms = timespec_to_ms(&end_time) - timespec_to_ms(&start_time); | ||
float time_ns = time_ms / LOOP_SIZE * 1000000; | ||
printf("Calculated in %.3f ns using %d workers.\n", | ||
time_ns, __cilkrts_get_nworkers()); | ||
#endif | ||
|
||
for(i=0;i<5;i++) { | ||
for(j=0;j<5;j++) { | ||
printf("%d ", c[i][j]); | ||
} | ||
printf("\n"); | ||
} | ||
|
||
} |
Oops, something went wrong.