set new number of cores
authorDavid Kaufmann <astra@ionic.at>
Fri, 20 Jan 2012 23:57:11 +0000 (00:57 +0100)
committerDavid Kaufmann <astra@ionic.at>
Fri, 20 Jan 2012 23:57:11 +0000 (00:57 +0100)
openmp/merge/sort.c

index 8d27047aac465d2922843c5094605c6848a9aa50..bee8bc661889751d7f727e8dfc1f6eee9f11ed9f 100644 (file)
@@ -5,6 +5,13 @@
 #include <omp.h>
 #include "numlist.h"
 
+#ifndef min
+       #define min( a, b ) ( ((a) < (b)) ? (a) : (b) )
+#endif
+#ifndef max
+       #define max( a, b ) ( ((a) > (b)) ? (a) : (b) )
+#endif
+
 typedef int numtype;
 
 void printlist(char * message, numtype * ptr, int len);
@@ -14,7 +21,7 @@ void merge(int ti, numtype * a, int n, numtype * b, int m, numtype * c);
 
 int main ( int argc, char ** argv) {
        int n = LISTSIZE, m = LISTSIZE;
-       int p = 1;
+       int p = min(omp_get_num_procs(), n);
        int opt, i;
        int a_len, b_len, b_len_end, b_len_begin;
        numtype * c;
@@ -31,7 +38,7 @@ int main ( int argc, char ** argv) {
                }
        }
 
-       //printf ("Maximal number of threads: %i\n", omp_get_max_threads());
+       printf ("Number of processes that will be started: %i\n", p);
        //printf ("----------------------------------\n");
 
        c = (numtype *) malloc((LISTSIZE * 2 + 1) * (sizeof (numtype)));