Skip to content

Commit 39daf7a

Browse files
authored
Merge pull request #6104 from hoopoepg/topic/oshmem-zero-len-coll
OSHMEM: added processing of zero-length collectives
2 parents cd199d0 + c93927e commit 39daf7a

File tree

10 files changed

+63
-17
lines changed

10 files changed

+63
-17
lines changed

oshmem/mca/scoll/basic/scoll_basic_alltoall.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ int mca_scoll_basic_alltoall(struct oshmem_group_t *group,
6161
return OSHMEM_ERR_BAD_PARAM;
6262
}
6363

64+
/* Do nothing on zero-length request */
65+
if (OPAL_UNLIKELY(!nelems)) {
66+
return OPAL_SUCCESS;
67+
}
68+
6469
if ((sst == 1) && (dst == 1)) {
6570
rc = a2a_alg_simple(group, target, source, nelems, element_size);
6671
} else {

oshmem/mca/scoll/basic/scoll_basic_broadcast.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ int mca_scoll_basic_broadcast(struct oshmem_group_t *group,
5555
if ((rc == OSHMEM_SUCCESS) && oshmem_proc_group_is_member(group)) {
5656
int i = 0;
5757

58+
/* Do nothing on zero-length request */
59+
if (OPAL_UNLIKELY(!nlong)) {
60+
return OSHMEM_SUCCESS;
61+
}
62+
5863
if (pSync) {
5964
alg = (alg == SCOLL_DEFAULT_ALG ?
6065
mca_scoll_basic_param_broadcast_algorithm : alg);

oshmem/mca/scoll/basic/scoll_basic_collect.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ int mca_scoll_basic_collect(struct oshmem_group_t *group,
6666
if ((rc == OSHMEM_SUCCESS) && oshmem_proc_group_is_member(group)) {
6767
int i = 0;
6868

69+
/* Do nothing on zero-length request */
70+
if (OPAL_UNLIKELY(!nlong)) {
71+
return OPAL_SUCCESS;
72+
}
73+
6974
if (nlong_type) {
7075
alg = (alg == SCOLL_DEFAULT_ALG ?
7176
mca_scoll_basic_param_collect_algorithm : alg);

oshmem/mca/scoll/basic/scoll_basic_reduce.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ int mca_scoll_basic_reduce(struct oshmem_group_t *group,
7878
if ((rc == OSHMEM_SUCCESS) && oshmem_proc_group_is_member(group)) {
7979
int i = 0;
8080

81+
/* Do nothing on zero-length request */
82+
if (OPAL_UNLIKELY(!nlong)) {
83+
return OSHMEM_SUCCESS;
84+
}
85+
8186
if (pSync) {
8287
alg = (alg == SCOLL_DEFAULT_ALG ?
8388
mca_scoll_basic_param_reduce_algorithm : alg);

oshmem/mca/scoll/mpi/scoll_mpi_ops.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ int mca_scoll_mpi_broadcast(struct oshmem_group_t *group,
5454
}
5555
dtype = &ompi_mpi_char.dt;
5656
root = oshmem_proc_group_find_id(group, PE_root);
57+
58+
/* Do nothing on zero-length request */
59+
if (OPAL_UNLIKELY(!nlong)) {
60+
return OSHMEM_SUCCESS;
61+
}
62+
5763
/* Open SHMEM specification has the following constrains (page 85):
5864
* "If using C/C++, nelems must be of type integer. If you are using Fortran, it must be a
5965
* default integer value". And also fortran signature says "INTEGER".
@@ -104,6 +110,12 @@ int mca_scoll_mpi_collect(struct oshmem_group_t *group,
104110
void *sbuf, *rbuf;
105111
MPI_COLL_VERBOSE(20,"RUNNING MPI ALLGATHER");
106112
mpi_module = (mca_scoll_mpi_module_t *) group->g_scoll.scoll_collect_module;
113+
114+
/* Do nothing on zero-length request */
115+
if (OPAL_UNLIKELY(!nlong)) {
116+
return OSHMEM_SUCCESS;
117+
}
118+
107119
if (nlong_type == true) {
108120
sbuf = (void *) source;
109121
rbuf = target;
@@ -177,6 +189,12 @@ int mca_scoll_mpi_reduce(struct oshmem_group_t *group,
177189
dtype = shmem_dtype_to_ompi_dtype(op);
178190
h_op = shmem_op_to_ompi_op(op->op);
179191
count = nlong/op->dt_size;
192+
193+
/* Do nothing on zero-length request */
194+
if (OPAL_UNLIKELY(!nlong)) {
195+
return OSHMEM_SUCCESS;
196+
}
197+
180198
/* Open SHMEM specification has the following constrains (page 85):
181199
* "If using C/C++, nelems must be of type integer. If you are using Fortran, it must be a
182200
* default integer value". And also fortran signature says "INTEGER".

oshmem/runtime/runtime.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ OSHMEM_DECLSPEC int oshmem_shmem_register_params(void);
200200
RUNTIME_CHECK_ERROR("Required address %p is not in symmetric space\n", ((void*)x)); \
201201
oshmem_shmem_abort(-1); \
202202
}
203+
/* Check if address is in symmetric space or size is zero */
204+
#define RUNTIME_CHECK_ADDR_SIZE(x,s) \
205+
if (OPAL_UNLIKELY((s) && !MCA_MEMHEAP_CALL(is_symmetric_addr((x))))) \
206+
{ \
207+
RUNTIME_CHECK_ERROR("Required address %p is not in symmetric space\n", ((void*)x)); \
208+
oshmem_shmem_abort(-1); \
209+
}
203210
#define RUNTIME_CHECK_WITH_MEMHEAP_SIZE(x) \
204211
if (OPAL_UNLIKELY((long)(x) > MCA_MEMHEAP_CALL(size))) \
205212
{ \
@@ -212,6 +219,7 @@ OSHMEM_DECLSPEC int oshmem_shmem_register_params(void);
212219
#define RUNTIME_CHECK_INIT()
213220
#define RUNTIME_CHECK_PE(x)
214221
#define RUNTIME_CHECK_ADDR(x)
222+
#define RUNTIME_CHECK_ADDR_SIZE(x,s)
215223
#define RUNTIME_CHECK_WITH_MEMHEAP_SIZE(x)
216224

217225
#endif /* OSHMEM_PARAM_CHECK */

oshmem/shmem/c/shmem_alltoall.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void _shmem_alltoall(void *target,
3030
int PE_size,
3131
long *pSync);
3232

33-
#define SHMEM_TYPE_ALLTOALL(name, element_size) \
33+
#define SHMEM_TYPE_ALLTOALL(name, element_size) \
3434
void shmem##name(void *target, \
3535
const void *source, \
3636
size_t nelems, \
@@ -40,15 +40,15 @@ static void _shmem_alltoall(void *target,
4040
long *pSync) \
4141
{ \
4242
RUNTIME_CHECK_INIT(); \
43-
RUNTIME_CHECK_ADDR(target); \
44-
RUNTIME_CHECK_ADDR(source); \
43+
RUNTIME_CHECK_ADDR_SIZE(target, nelems); \
44+
RUNTIME_CHECK_ADDR_SIZE(source, nelems); \
4545
\
4646
_shmem_alltoall(target, source, 1, 1, nelems, element_size, \
4747
PE_start, logPE_stride, PE_size, \
4848
pSync); \
4949
}
5050

51-
#define SHMEM_TYPE_ALLTOALLS(name, element_size) \
51+
#define SHMEM_TYPE_ALLTOALLS(name, element_size) \
5252
void shmem##name(void *target, \
5353
const void *source, \
5454
ptrdiff_t dst, ptrdiff_t sst, \
@@ -59,8 +59,8 @@ static void _shmem_alltoall(void *target,
5959
long *pSync) \
6060
{ \
6161
RUNTIME_CHECK_INIT(); \
62-
RUNTIME_CHECK_ADDR(target); \
63-
RUNTIME_CHECK_ADDR(source); \
62+
RUNTIME_CHECK_ADDR_SIZE(target, nelems); \
63+
RUNTIME_CHECK_ADDR_SIZE(source, nelems); \
6464
\
6565
_shmem_alltoall(target, source, dst, sst, nelems, element_size, \
6666
PE_start, logPE_stride, PE_size, \

oshmem/shmem/c/shmem_broadcast.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void _shmem_broadcast(void *target,
2929
int PE_size,
3030
long *pSync);
3131

32-
#define SHMEM_TYPE_BROADCAST(name, element_size) \
32+
#define SHMEM_TYPE_BROADCAST(name, element_size) \
3333
void shmem##name( void *target, \
3434
const void *source, \
3535
size_t nelems, \
@@ -40,10 +40,10 @@ static void _shmem_broadcast(void *target,
4040
long *pSync) \
4141
{ \
4242
RUNTIME_CHECK_INIT(); \
43-
RUNTIME_CHECK_ADDR(target); \
44-
RUNTIME_CHECK_ADDR(source); \
43+
RUNTIME_CHECK_ADDR_SIZE(target, nelems); \
44+
RUNTIME_CHECK_ADDR_SIZE(source, nelems); \
4545
\
46-
_shmem_broadcast( target, source, nelems * element_size, \
46+
_shmem_broadcast( target, source, nelems * element_size, \
4747
PE_root, PE_start, logPE_stride, PE_size, \
4848
pSync); \
4949
}

oshmem/shmem/c/shmem_collect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ static void _shmem_collect(void *target,
3939
long *pSync) \
4040
{ \
4141
RUNTIME_CHECK_INIT(); \
42-
RUNTIME_CHECK_ADDR(target); \
43-
RUNTIME_CHECK_ADDR(source); \
42+
RUNTIME_CHECK_ADDR_SIZE(target, nelems); \
43+
RUNTIME_CHECK_ADDR_SIZE(source, nelems); \
4444
\
45-
_shmem_collect( target, source, nelems * element_size, \
45+
_shmem_collect( target, source, nelems * element_size, \
4646
PE_start, logPE_stride, PE_size, \
4747
pSync, \
4848
nelems_type); \

oshmem/shmem/c/shmem_reduce.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
* object of every PE in the active set. The active set of PEs is defined by the triple PE_start,
2727
* logPE_stride and PE_size.
2828
*/
29-
#define SHMEM_TYPE_REDUCE_OP(name, type_name, type, prefix) \
30-
void prefix##type_name##_##name##_to_all( type *target, \
29+
#define SHMEM_TYPE_REDUCE_OP(name, type_name, type, prefix) \
30+
void prefix##type_name##_##name##_to_all( type *target, \
3131
const type *source, \
3232
int nreduce, \
3333
int PE_start, \
@@ -40,8 +40,8 @@
4040
oshmem_group_t* group = NULL; \
4141
\
4242
RUNTIME_CHECK_INIT(); \
43-
RUNTIME_CHECK_ADDR(target); \
44-
RUNTIME_CHECK_ADDR(source); \
43+
RUNTIME_CHECK_ADDR_SIZE(target, nreduce); \
44+
RUNTIME_CHECK_ADDR_SIZE(source, nreduce); \
4545
\
4646
{ \
4747
group = oshmem_proc_group_create_nofail(PE_start, 1<<logPE_stride, PE_size); \

0 commit comments

Comments
 (0)