From 605cdf887a61eaa7aabc770ccd85d82febbc5060 Mon Sep 17 00:00:00 2001 From: David Kaufmann Date: Fri, 28 Oct 2011 15:06:02 +0200 Subject: [PATCH] updated, funktioniert mit teilern von LISTLENGTH --- openmp/merge/sort.c | 23 +++++++++++++++-------- openmp/merge/test_threads.sh | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100755 openmp/merge/test_threads.sh diff --git a/openmp/merge/sort.c b/openmp/merge/sort.c index 13957f3..76434eb 100644 --- a/openmp/merge/sort.c +++ b/openmp/merge/sort.c @@ -5,7 +5,6 @@ #include #define LISTSIZE 10 -#define THREADS 2 void printlist(char * message, int * ptr) { printf (message); @@ -72,13 +71,24 @@ void merge(int ti, int * a, int n, int * b, int m, int * c) { int main ( int argc, char ** argv) { int n = LISTSIZE; - int p = THREADS; - int i; + 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,99,-1}; - int b[] = {1,2,7,34,35,68,77,78,79,84,-1}; + 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) { + switch (opt) { + case 't': + p = atoi(optarg); + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-t threads]\n", argv[0]); + exit(EXIT_FAILURE); + } + } + printf ("----------------------------------\n"); c = (int *) malloc((LISTSIZE * 2 + 1) * (sizeof (int))); @@ -102,9 +112,6 @@ int main ( int argc, char ** argv) { } 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]); - if (b_len == 0) { - continue; - } merge( i+1, &a[i*a_len], a_len, diff --git a/openmp/merge/test_threads.sh b/openmp/merge/test_threads.sh new file mode 100755 index 0000000..f35f26e --- /dev/null +++ b/openmp/merge/test_threads.sh @@ -0,0 +1,2 @@ +#!/bin/bash +for i in $(seq 10); do ./sort -t $i | grep "Sorted List:" | sed "s/Sorted List:/$i:/"; done; -- 2.43.0