Use MPI_ANY_SOURCE when receiving sorted lists in sorting/soln/main.c.
authorW. Trevor King <wking@drexel.edu>
Wed, 27 Oct 2010 12:20:52 +0000 (08:20 -0400)
committerW. Trevor King <wking@drexel.edu>
Wed, 27 Oct 2010 12:20:52 +0000 (08:20 -0400)
assignments/archive/sorting/soln/main.c

index be238b4d08dfd62812fa8316389c8dc254bfbd7d..0810318ab6ec3a51ed527e80bf92095325806789 100644 (file)
@@ -275,17 +275,18 @@ void master(int rank, int size, const char *file_name)
        }
 
        for (i = 1; i < size; i++) {
-#ifdef DEBUG
-               fprintf(stderr, "receive sorted data chunk from node %d\n", i);
-#endif                         /* DEBUG */
-               err = MPI_Recv(arrays[i], chunk_size, MPI_DOUBLE, i, TAG_SORTED,
-                              MPI_COMM_WORLD, &status);
+               err = MPI_Recv(arrays[i], chunk_size, MPI_DOUBLE,
+                              MPI_ANY_SOURCE, TAG_SORTED, MPI_COMM_WORLD,
+                              &status);
                if (err != 0) {
                        fprintf(stderr,
-                               "error receiving sorted block from %d\n", i);
+                               "error receiving sorted block from %d\n",
+                               status.MPI_SOURCE);
                        exit(EXIT_FAILURE);
                }
 #ifdef DEBUG
+               fprintf(stderr, "received sorted data chunk from node %d\n",
+                       status.MPI_SOURCE);
                printarray(stderr, chunk_size, arrays[i], NUM_SHOWN);
                fprintf(stderr, "check: sum of %d elements = %g\n",
                        chunk_size, checkarray(chunk_size, arrays[i]));