From deeb55bd5980396142f215f0d52e5e08f40e7dd7 Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Tue, 1 Nov 2011 18:46:18 +0100 Subject: [PATCH] arrays containing 10,000,000 values --- openmp/merge/Makefile | 6 +++--- openmp/merge/generate_random.sh | 28 ++++++++++++++++++++++++++++ openmp/merge/numlist1.h | 1 + openmp/merge/numlist2.h | 1 + openmp/merge/sort.c | 23 +++++++++++++---------- openmp/merge/test_threads.sh | 5 ++++- 6 files changed, 50 insertions(+), 14 deletions(-) create mode 100755 openmp/merge/generate_random.sh create mode 100644 openmp/merge/numlist1.h create mode 100644 openmp/merge/numlist2.h diff --git a/openmp/merge/Makefile b/openmp/merge/Makefile index f8efee4..1085bf0 100644 --- a/openmp/merge/Makefile +++ b/openmp/merge/Makefile @@ -1,7 +1,7 @@ # GCC Makefile CC = gcc -CFLAGS = -pedantic -Wall -g -fopenmp +CFLAGS = -pedantic -Wall -g -fopenmp -O0 LDFLAGS = -fopenmp BINARIES = sort @@ -9,8 +9,8 @@ OBJECTS = $(BINARIES).o all: sort -sort: sort.o - $(CC) -o $@ $< $(LDFLAGS) +sort: sort.o numlist1.o numlist2.o + $(CC) -o $@ $? $(LDFLAGS) %.o: %.c $(CC) $(CFLAGS) -c $< diff --git a/openmp/merge/generate_random.sh b/openmp/merge/generate_random.sh new file mode 100755 index 0000000..4a7f68b --- /dev/null +++ b/openmp/merge/generate_random.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +function pwait() { + while [ $(jobs -r | wc -l) -gt 0 ]; + do + sleep 1 + done +} + +echo "generating numbers" +#echo ` unsorted1a & +#echo ` unsorted1b & +#echo ` unsorted2a & +#echo ` unsorted2b & + +pwait + +echo "removing empty lines" +rm unsorted1 unsorted2 +sed '/^$/d' unsorted1a >> unsorted1 +sed '/^$/d' unsorted1b >> unsorted1 +sed '/^$/d' unsorted2a >> unsorted2 +sed '/^$/d' unsorted2b >> unsorted2 + +echo "formatting numlist" +cat unsorted1 | sort -n | sed -e ':a;N;$!ba;s/\n/,/g' -e 's/^/,/' -e 's/,[0]*/,/g' -e 's/^,/\tint a[] = {/' -e 's/$/,-1};/' >numlist1.c & +cat unsorted2 | sort -n | sed -e ':a;N;$!ba;s/\n/,/g' -e 's/^/,/' -e 's/,[0]*/,/g' -e 's/^,/\tint b[] = {/' -e 's/$/,-1};/' >numlist2.c & +pwait diff --git a/openmp/merge/numlist1.h b/openmp/merge/numlist1.h new file mode 100644 index 0000000..4b47834 --- /dev/null +++ b/openmp/merge/numlist1.h @@ -0,0 +1 @@ +extern int a[10000001]; diff --git a/openmp/merge/numlist2.h b/openmp/merge/numlist2.h new file mode 100644 index 0000000..5098b8d --- /dev/null +++ b/openmp/merge/numlist2.h @@ -0,0 +1 @@ +extern int b[10000001]; diff --git a/openmp/merge/sort.c b/openmp/merge/sort.c index 63231ae..4e32478 100644 --- a/openmp/merge/sort.c +++ b/openmp/merge/sort.c @@ -3,8 +3,10 @@ #include #include #include +#include "numlist1.h" +#include "numlist2.h" -#define LISTSIZE 10 +#define LISTSIZE 10000000 void printlist(char * message, int * ptr) { printf (message); @@ -18,6 +20,7 @@ void printlist(char * message, int * ptr) { int rank(int elem, int * list) { int pos; + //usleep(2000);//2ms pos = 0; if (elem == -1) { return -1; } while (*list >= 0) { @@ -35,13 +38,14 @@ int rank(int elem, int * list) { void merge(int ti, int * a, int n, int * b, int m, int * c) { int sum; int i; - sleep (1); +// usleep (1000);//1ms /*printf ("sorting a:%i (%i) and b:%i (%i)\n", *a, n, *b, m);*/ if (m<0) { m=0;} if (n<0) { n=0;} sum = n + m; //printf ("%i modifying %i (%i+%i) (c[%i]/0x%08x -> c[%i]/0x%08x)\n", ti, sum, n, m, 0, (unsigned int) &c, sum-1, ((unsigned int) &c)+sum); for (i = 0; i < sum; i++) { + //usleep (1000);//1ms // n+m == 0 if (*a < 0 && *b < 0) { printf ("%i Calculation failed somehow...\n", ti); @@ -73,8 +77,6 @@ int main ( int argc, char ** argv) { int p = 1; int opt, i; int a_len, b_len, b_len_end, b_len_begin; - int a[] = {0,3,4,14,61,62,70,72,74,84,-1}; - int b[] = {1,2,7,34,35,68,77,78,79,99,-1}; int * c; while ((opt = getopt(argc, argv, "t:")) != -1) { @@ -89,13 +91,13 @@ int main ( int argc, char ** argv) { } //printf ("Maximal number of threads: %i\n", omp_get_max_threads()); - printf ("----------------------------------\n"); + //printf ("----------------------------------\n"); c = (int *) malloc((LISTSIZE * 2 + 1) * (sizeof (int))); c[LISTSIZE*2] = -1; - printlist("0 Sorted List A:", a); - printlist("0 Sorted List B:", b); + //printlist("0 Sorted List A:", a); + //printlist("0 Sorted List B:", b); a_len = n/p; #pragma omp parallel for shared(a,b,c,n,p,a_len) private(i,b_len_begin,b_len_end,b_len) @@ -107,11 +109,11 @@ int main ( int argc, char ** argv) { b_len_begin = n; } if (b_len_end < 0) { - printf ("Reached end of list!\n"); + //printf ("Reached end of list!\n"); b_len_end = n; } b_len = b_len_end - b_len_begin; - printf ("%i a_len: %i, b_len: %i (begin:%i ([%i]) -> end:%i [%i])\n", i+1, a_len, b_len, b_len_begin, b[b_len_begin], b_len_end, b[b_len_end]); + //printf ("%i a_len: %i, b_len: %i (begin:%i ([%i]) -> end:%i [%i])\n", i+1, a_len, b_len, b_len_begin, b[b_len_begin], b_len_end, b[b_len_end]); merge( i+1, &a[i*a_len], a_len, @@ -120,7 +122,8 @@ int main ( int argc, char ** argv) { &c[i*a_len+b_len_begin]); } - printlist("Sorted List:", c); + //printlist("Sorted List:", c); free(c); return 0; } + diff --git a/openmp/merge/test_threads.sh b/openmp/merge/test_threads.sh index f35f26e..68ef763 100755 --- a/openmp/merge/test_threads.sh +++ b/openmp/merge/test_threads.sh @@ -1,2 +1,5 @@ #!/bin/bash -for i in $(seq 10); do ./sort -t $i | grep "Sorted List:" | sed "s/Sorted List:/$i:/"; done; +#for i in 1 2 5 10; do ./sort -t $i | grep "Sorted List:" | sed "s/Sorted List:/$i:/"; done; +#for i in 1 2 5 10; do time ./sort -t $i | sed "s/Sorted List:/$i:/"; done; +#for i in 1 2 5 10; do echo $i; time ./sort -t $i; done; +for i in 1 2 4 5 8 10 20 25 40 50 100 125 200 250 500 1000; do echo -n "$i: "; /usr/bin/time -f "%E" ./sort -t $i; done; -- 2.43.0