--- /dev/null
+#!/bin/bash
+
+function pwait() {
+ while [ $(jobs -r | wc -l) -gt 0 ];
+ do
+ sleep 1
+ done
+}
+
+echo "generating numbers"
+#echo `</dev/urandom tr -dc 0-9 | head -c40000000` | sed 's/\(........\)/\1\n/g' > unsorted1a &
+#echo `</dev/urandom tr -dc 0-9 | head -c40000000` | sed 's/\(........\)/\1\n/g' > unsorted1b &
+#echo `</dev/urandom tr -dc 0-9 | head -c40000000` | sed 's/\(........\)/\1\n/g' > unsorted2a &
+#echo `</dev/urandom tr -dc 0-9 | head -c40000000` | sed 's/\(........\)/\1\n/g' > 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
#include <omp.h>
#include <stdlib.h>
#include <unistd.h>
+#include "numlist1.h"
+#include "numlist2.h"
-#define LISTSIZE 10
+#define LISTSIZE 10000000
void printlist(char * message, int * ptr) {
printf (message);
int rank(int elem, int * list) {
int pos;
+ //usleep(2000);//2ms
pos = 0;
if (elem == -1) { return -1; }
while (*list >= 0) {
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);
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) {
}
//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)
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,
&c[i*a_len+b_len_begin]);
}
- printlist("Sorted List:", c);
+ //printlist("Sorted List:", c);
free(c);
return 0;
}
+