[mpich2-commits] r9469 - in mpich2/trunk: src/mpi/comm test/mpi/comm

goodell at mcs.anl.gov goodell at mcs.anl.gov
Wed Feb 1 17:51:32 CST 2012


Author: goodell
Date: 2012-02-01 17:51:32 -0600 (Wed, 01 Feb 2012)
New Revision: 9469

Added:
   mpich2/trunk/test/mpi/comm/ic2.c
Modified:
   mpich2/trunk/src/mpi/comm/intercomm_create.c
   mpich2/trunk/test/mpi/comm/Makefile.am
   mpich2/trunk/test/mpi/comm/testlist
Log:
tt#1574: bad loop bounds in intercomm_create error checking

Thanks to N. Radclif @ Cray for the bug report, proposed fix, and
regression test case.  Note that the fix in this commit is more complete
than the one originally proposed in that ticket.

No reviewer.

Modified: mpich2/trunk/src/mpi/comm/intercomm_create.c
===================================================================
--- mpich2/trunk/src/mpi/comm/intercomm_create.c	2012-01-31 05:23:16 UTC (rev 9468)
+++ mpich2/trunk/src/mpi/comm/intercomm_create.c	2012-02-01 23:51:32 UTC (rev 9469)
@@ -54,19 +54,21 @@
 	if (lpids2[i] > maxlpid) maxlpid = lpids2[i];
     }
 
-    /* Compute the max index and zero the pids array */
-    maxi = (maxlpid + 31) / 32;
+    /* Compute the max index */
+    maxi = (maxlpid + 31) / 32; /* round-up division */
 
     if (maxi >= MAX_LPID32_ARRAY) {
-	MPIU_CHKLMEM_MALLOC(lpidmask,int32_t*,maxi*sizeof(int32_t),
+        /* maxi+1 elements b/c maxi is the last index, not size */
+	MPIU_CHKLMEM_MALLOC(lpidmask,int32_t*,(maxi+1)*sizeof(int32_t),
 			    mpi_errno,"lpidmask");
     }
     else {
 	lpidmask = lpidmaskPrealloc;
     }
-    
-    for (i=0; i<maxi; i++) lpidmask[i] = 0;
 
+    /* zero the bitvector array */
+    memset(lpidmask, 0x00, (maxi+1)*sizeof(*lpidmask));
+
     /* Set the bits for the first array */
     for (i=0; i<n1; i++) {
 	idx = lpids1[i] / 32;

Modified: mpich2/trunk/test/mpi/comm/Makefile.am
===================================================================
--- mpich2/trunk/test/mpi/comm/Makefile.am	2012-01-31 05:23:16 UTC (rev 9468)
+++ mpich2/trunk/test/mpi/comm/Makefile.am	2012-02-01 23:51:32 UTC (rev 9469)
@@ -17,6 +17,7 @@
     dup               \
     dupic             \
     ic1               \
+    ic2               \
     commname          \
     ctxalloc          \
     ctxsplit          \

Added: mpich2/trunk/test/mpi/comm/ic2.c
===================================================================
--- mpich2/trunk/test/mpi/comm/ic2.c	                        (rev 0)
+++ mpich2/trunk/test/mpi/comm/ic2.c	2012-02-01 23:51:32 UTC (rev 9469)
@@ -0,0 +1,84 @@
+/* -*- Mode: C; c-basic-offset:4 ; -*- */
+/*
+ *
+ *  (C) 2012 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* regression test for ticket #1574
+ *
+ * Based on test code from N. Radclif @ Cray. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <mpi.h>
+
+int main(int argc, char **argv)
+{
+    MPI_Comm c0, c1, ic;
+    MPI_Group g0, g1, gworld;
+    int a, b, c, d;
+    int rank, size, remote_leader, tag;
+    int ranks[2];
+
+    tag = 5;
+    c0 = c1 = ic = MPI_COMM_NULL;
+    g0 = g1 = gworld = MPI_GROUP_NULL;
+
+    MPI_Init(&argc, &argv);
+
+    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+    MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+    if (size < 33) {
+        printf("ERROR: this test requires at least 33 processes\n");
+        MPI_Abort(MPI_COMM_WORLD, 1);
+        return 1;
+    }
+
+    /* group of c0
+     * NOTE: a>=32 is essential for exercising the loop bounds bug from tt#1574 */
+    a = 32;
+    b = 24;
+
+    /* group of c1 */
+    c = 25;
+    d = 26;
+
+    MPI_Comm_group(MPI_COMM_WORLD, &gworld);
+
+    ranks[0] = a;
+    ranks[1] = b;
+    MPI_Group_incl(gworld, 2, ranks, &g0);
+    MPI_Comm_create(MPI_COMM_WORLD, g0, &c0);
+
+    ranks[0] = c;
+    ranks[1] = d;
+    MPI_Group_incl(gworld, 2, ranks, &g1);
+    MPI_Comm_create(MPI_COMM_WORLD, g1, &c1);
+
+    if (rank == a || rank == b) {
+        remote_leader = c;
+        MPI_Intercomm_create(c0, 0, MPI_COMM_WORLD, remote_leader, tag, &ic);
+    }
+    else if (rank == c || rank == d) {
+        remote_leader = a;
+        MPI_Intercomm_create(c1, 0, MPI_COMM_WORLD, remote_leader, tag, &ic);
+    }
+
+    MPI_Group_free(&g0);
+    MPI_Group_free(&g1);
+    MPI_Group_free(&gworld);
+
+    if (c0 != MPI_COMM_NULL)
+        MPI_Comm_free(&c0);
+    if (c1 != MPI_COMM_NULL)
+        MPI_Comm_free(&c1);
+    if (ic != MPI_COMM_NULL)
+        MPI_Comm_free(&ic);
+
+    MPI_Finalize();
+
+    return 0;
+}
+

Modified: mpich2/trunk/test/mpi/comm/testlist
===================================================================
--- mpich2/trunk/test/mpi/comm/testlist	2012-01-31 05:23:16 UTC (rev 9468)
+++ mpich2/trunk/test/mpi/comm/testlist	2012-02-01 23:51:32 UTC (rev 9469)
@@ -3,6 +3,8 @@
 commcreate1 8
 commname 4
 ic1 4
+# ic2 needs an unusually large number of processes (>= 33)
+ic2 33
 icgroup 8
 icm 8
 icsplit 8



More information about the mpich2-commits mailing list