From fabb1192c7c13f1d1028944d57693f51d28aa60d Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Fri, 25 Nov 2011 02:48:05 +0100 Subject: [PATCH] update sort.c, cleanup merge.plt --- openmp/merge/merge.plt | 11 +++++------ openmp/merge/sort.c | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/openmp/merge/merge.plt b/openmp/merge/merge.plt index 0728940..abb2d0e 100644 --- a/openmp/merge/merge.plt +++ b/openmp/merge/merge.plt @@ -4,11 +4,10 @@ set grid set title "Merging times" set xlabel "value of parameter p" set ylabel "seconds per sort run" -set xrange [ 1.0000 : 250.0 ] # Aufteilung in p Teile -set yrange [ 0.0000 : 2.0 ] # Sekunden pro sort -set xtics 25,25,500 -set ytics 0.25,0.25,3.75 +set xrange [ 1.0000 : 200.0 ] # Aufteilung in p Teile +set yrange [ 0.0000 : 0.75 ] # Sekunden pro sort +set xtics 0,25,200 +set ytics 0,0.1,0.75 set datafile separator "," plot 'merge.dat' using 1:2 notitle with points, \ - 'merge.dat' using 1:2 title "interpolate" with lines, \ - 'merge.dat' using 1:2 smooth csplines title "cspline" with lines + 'merge.dat' using 1:2 title "interpolate" with lines diff --git a/openmp/merge/sort.c b/openmp/merge/sort.c index 03ed112..88a3b1c 100644 --- a/openmp/merge/sort.c +++ b/openmp/merge/sort.c @@ -7,8 +7,8 @@ #define ATYPE int -void printlist(char * message, int * ptr); -int rank(int elem, int * list); +void printlist(char * message, ATYPE * ptr, int len); +int rank(int elem, ATYPE * list, int len); /* merge(a,n,b,m,c): merges a of size n and b of size m into c */ void merge(int ti, ATYPE * a, int n, ATYPE * b, int m, ATYPE * c); @@ -45,8 +45,8 @@ int main ( int argc, char ** argv) { a_len = n/p; #pragma omp parallel for shared(a,b,c,n,m,p,a_len) private(i,b_len_begin,b_len_end,b_len) for (i = 0; i < p; i++) { - b_len_begin = rank(a[i*a_len], b); - b_len_end = rank(a[(i+1)*a_len], b); + b_len_begin = rank(a[i*a_len], b, m); + b_len_end = rank(a[(i+1)*a_len], b, m); if (b_len_begin < 0) { printf ("Insert to end of list!\n"); b_len_begin = n; @@ -73,29 +73,31 @@ int main ( int argc, char ** argv) { return 0; } -void printlist(char * message, ATYPE * ptr) { +void printlist(char * message, ATYPE * ptr, int len) { printf (message); - while (*ptr != -1) { + while (len > 0) { printf (" %i", *ptr); - ptr++; + ptr++; len--; } printf ("\n"); } -int rank(ATYPE elem, ATYPE * list) { +int rank(ATYPE elem, ATYPE * list, int len) { int pos; + int i = len; pos = 0; if (elem == -1) { return -1; } - while (*list >= 0) { + while (i > 0) { /*printf ("elem_list: %i %i\n", elem, *list);*/ if (elem <= *list) { return pos; } list++; pos++; + i--; } - return -1; + return len; } void merge(int ti, ATYPE * a, int n, ATYPE * b, int m, int * c) { @@ -126,6 +128,6 @@ void merge(int ti, ATYPE * a, int n, ATYPE * b, int m, int * c) { } } } - printf ("merge done, n=%d, m=%d\n", n, m); + // printf ("merge done, n=%d, m=%d\n", n, m); return; } -- 2.43.0