@@ -30,7 +30,6 @@ static pthread_mutex_t gmr_list_mutex = PTHREAD_MUTEX_INITIALIZER;
3030 */
3131gmr_t * gmr_create (gmr_size_t local_size , void * * base_ptrs , ARMCI_Group * group ) {
3232 int i ;
33- gmr_size_t aggregate_size ;
3433 int alloc_me , alloc_nproc ;
3534 int world_me , world_nproc ;
3635 MPI_Group world_group , alloc_group ;
@@ -40,6 +39,21 @@ gmr_t *gmr_create(gmr_size_t local_size, void **base_ptrs, ARMCI_Group *group) {
4039 ARMCII_Assert (local_size >= 0 );
4140 ARMCII_Assert (group != NULL );
4241
42+ /* determine if the GMR construction is pointless and exit early */
43+ {
44+ gmr_size_t max_local_size = 1 <<30 ;
45+
46+ /* if gmr_size_t changes from long, this needs to change... */
47+ MPI_Allreduce (& local_size , & max_local_size , 1 , MPI_LONG , MPI_MAX , group -> comm );
48+
49+ if (max_local_size == 0 ) {
50+ for (i = 0 ; i < alloc_nproc ; i ++ ) {
51+ base_ptrs [i ] = NULL ;
52+ }
53+ return NULL ;
54+ }
55+ }
56+
4357 MPI_Comm_rank (group -> comm , & alloc_me );
4458 MPI_Comm_size (group -> comm , & alloc_nproc );
4559 MPI_Comm_rank (ARMCI_GROUP_WORLD .comm , & world_me );
@@ -114,24 +128,6 @@ gmr_t *gmr_create(gmr_size_t local_size, void **base_ptrs, ARMCI_Group *group) {
114128 MPI_Allgather ( & gmr_slice , sizeof (gmr_slice_t ), MPI_BYTE ,
115129 alloc_slices , sizeof (gmr_slice_t ), MPI_BYTE , group -> comm );
116130
117- /* Check for a global size 0 allocation */
118- for (i = aggregate_size = 0 ; i < alloc_nproc ; i ++ ) {
119- aggregate_size += alloc_slices [i ].size ;
120- }
121-
122- /* Everyone asked for 0 bytes, return a NULL vector */
123- if (aggregate_size == 0 ) {
124- free (alloc_slices );
125- free (mreg -> slices );
126- MPI_Win_free (& mreg -> window );
127- free (mreg );
128-
129- for (i = 0 ; i < alloc_nproc ; i ++ )
130- base_ptrs [i ] = NULL ;
131-
132- return NULL ;
133- }
134-
135131 /* Populate the base pointers array */
136132 for (i = 0 ; i < alloc_nproc ; i ++ )
137133 base_ptrs [i ] = alloc_slices [i ].base ;
0 commit comments