Skip to content

Commit 1d8fbfe

Browse files
committed
Merge pull request #1478 from igor-ivanov/pr/oshmem-v1.3-alltoall
oshmem: Add alltoall
2 parents 7483a66 + 1bed5d8 commit 1d8fbfe

27 files changed

+788
-13
lines changed

oshmem/include/shmem.h.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ enum shmem_wait_ops {
101101
#define _SHMEM_BCAST_SYNC_SIZE (1 + _SHMEM_BARRIER_SYNC_SIZE)
102102
#define _SHMEM_COLLECT_SYNC_SIZE (1 + _SHMEM_BCAST_SYNC_SIZE)
103103
#define _SHMEM_REDUCE_SYNC_SIZE (1 + _SHMEM_BCAST_SYNC_SIZE)
104+
#define _SHMEM_ALLTOALL_SYNC_SIZE (1)
104105
#define _SHMEM_REDUCE_MIN_WRKDATA_SIZE (1)
105106
#define _SHMEM_SYNC_VALUE (-1)
106107

107108
#define SHMEM_BARRIER_SYNC_SIZE _SHMEM_BARRIER_SYNC_SIZE
108109
#define SHMEM_BCAST_SYNC_SIZE _SHMEM_BCAST_SYNC_SIZE
109110
#define SHMEM_COLLECT_SYNC_SIZE _SHMEM_COLLECT_SYNC_SIZE
110111
#define SHMEM_REDUCE_SYNC_SIZE _SHMEM_REDUCE_SYNC_SIZE
112+
#define SHMEM_ALLTOALL_SYNC_SIZE _SHMEM_ALLTOALL_SYNC_SIZE
111113
#define SHMEM_REDUCE_MIN_WRKDATA_SIZE _SHMEM_REDUCE_MIN_WRKDATA_SIZE
112114
#define SHMEM_SYNC_VALUE _SHMEM_SYNC_VALUE
113115

@@ -344,6 +346,11 @@ OSHMEM_DECLSPEC void shmem_collect32(void *target, const void *source, size_t nl
344346
OSHMEM_DECLSPEC void shmem_collect64(void *target, const void *source, size_t nlong, int PE_start, int logPE_stride, int PE_size, long *pSync);
345347
OSHMEM_DECLSPEC void shmem_fcollect32(void *target, const void *source, size_t nlong, int PE_start, int logPE_stride, int PE_size, long *pSync);
346348
OSHMEM_DECLSPEC void shmem_fcollect64(void *target, const void *source, size_t nlong, int PE_start, int logPE_stride, int PE_size, long *pSync);
349+
OSHMEM_DECLSPEC void shmem_alltoall32(void *target, const void *source, size_t nelems, int PE_start, int logPE_stride, int PE_size, long *pSync);
350+
OSHMEM_DECLSPEC void shmem_alltoall64(void *target, const void *source, size_t nelems, int PE_start, int logPE_stride, int PE_size, long *pSync);
351+
OSHMEM_DECLSPEC void shmem_alltoalls32(void *target, const void *source, ptrdiff_t dst, ptrdiff_t sst, size_t nelems, int PE_start, int logPE_stride, int PE_size, long *pSync);
352+
OSHMEM_DECLSPEC void shmem_alltoalls64(void *target, const void *source, ptrdiff_t dst, ptrdiff_t sst, size_t nelems, int PE_start, int logPE_stride, int PE_size, long *pSync);
353+
347354

348355
/*
349356
* Reduction routines

oshmem/mca/scoll/base/scoll_base_frame.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static void scoll_base_module_construct(mca_scoll_base_module_t *m)
4646
m->scoll_broadcast = NULL;
4747
m->scoll_collect = NULL;
4848
m->scoll_reduce = NULL;
49+
m->scoll_alltoall = NULL;
4950
m->scoll_module_enable = NULL;
5051
}
5152

oshmem/mca/scoll/base/scoll_base_select.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ static int scoll_null_reduce(struct oshmem_group_t *group,
118118
return OSHMEM_SUCCESS;
119119
}
120120

121+
static int scoll_null_alltoall(struct oshmem_group_t *group,
122+
void *target,
123+
const void *source,
124+
ptrdiff_t dst, ptrdiff_t sst,
125+
size_t nlong,
126+
long *pSync,
127+
int alg)
128+
{
129+
if (oshmem_proc_group_is_member(group)) {
130+
SCOLL_ERROR("internal error");
131+
oshmem_shmem_abort(-1);
132+
return OSHMEM_ERROR;
133+
}
134+
return OSHMEM_SUCCESS;
135+
}
136+
121137
/*
122138
* Stuff for the OBJ interface
123139
*/
@@ -160,6 +176,7 @@ int mca_scoll_base_group_unselect(struct oshmem_group_t * group)
160176
CLOSE(group, broadcast);
161177
CLOSE(group, collect);
162178
CLOSE(group, reduce);
179+
CLOSE(group, alltoall);
163180

164181
/* All done */
165182
return OSHMEM_SUCCESS;
@@ -184,6 +201,7 @@ int mca_scoll_base_select(struct oshmem_group_t *group)
184201
group->g_scoll.scoll_broadcast = scoll_null_broadcast;
185202
group->g_scoll.scoll_collect = scoll_null_collect;
186203
group->g_scoll.scoll_reduce = scoll_null_reduce;
204+
group->g_scoll.scoll_alltoall = scoll_null_alltoall;
187205
return OSHMEM_SUCCESS;
188206
}
189207
SCOLL_VERBOSE(10,
@@ -206,10 +224,11 @@ int mca_scoll_base_select(struct oshmem_group_t *group)
206224
if (OSHMEM_SUCCESS != ret) {
207225
mca_scoll_base_group_unselect(group);
208226
} else {
227+
COPY(avail->ac_module, group, barrier);
209228
COPY(avail->ac_module, group, broadcast);
210229
COPY(avail->ac_module, group, collect);
211230
COPY(avail->ac_module, group, reduce);
212-
COPY(avail->ac_module, group, barrier);
231+
COPY(avail->ac_module, group, alltoall);
213232
}
214233
OBJ_RELEASE(avail->ac_module);
215234
OBJ_RELEASE(avail);
@@ -220,16 +239,17 @@ int mca_scoll_base_select(struct oshmem_group_t *group)
220239
if ((NULL == group->g_scoll.scoll_barrier)
221240
|| (NULL == group->g_scoll.scoll_broadcast)
222241
|| (NULL == group->g_scoll.scoll_collect)
223-
|| (NULL == group->g_scoll.scoll_reduce)) {
242+
|| (NULL == group->g_scoll.scoll_reduce)
243+
|| (NULL == group->g_scoll.scoll_alltoall)) {
224244
mca_scoll_base_group_unselect(group);
225245
return OSHMEM_ERR_NOT_FOUND;
226246
}
227247

228248
return OSHMEM_SUCCESS;
229249
}
230250

231-
static int avail_coll_compare (opal_list_item_t **a,
232-
opal_list_item_t **b)
251+
static int avail_coll_compare(opal_list_item_t **a,
252+
opal_list_item_t **b)
233253
{
234254
avail_com_t *acom = (avail_com_t *) *a;
235255
avail_com_t *bcom = (avail_com_t *) *b;

oshmem/mca/scoll/basic/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2013 Mellanox Technologies, Inc.
2+
# Copyright (c) 2013-2016 Mellanox Technologies, Inc.
33
# All rights reserved.
44
# $COPYRIGHT$
55
#
@@ -15,7 +15,8 @@ sources = \
1515
scoll_basic_barrier.c \
1616
scoll_basic_broadcast.c \
1717
scoll_basic_collect.c \
18-
scoll_basic_reduce.c
18+
scoll_basic_reduce.c \
19+
scoll_basic_alltoall.c
1920

2021

2122
# Make the output library in this directory, and name it either

oshmem/mca/scoll/basic/scoll_basic.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013 Mellanox Technologies, Inc.
2+
* Copyright (c) 2013-2016 Mellanox Technologies, Inc.
33
* All rights reserved.
44
* $COPYRIGHT$
55
*
@@ -77,6 +77,14 @@ int mca_scoll_basic_reduce(struct oshmem_group_t *group,
7777
long *pSync,
7878
void *pWrk,
7979
int alg);
80+
int mca_scoll_basic_alltoall(struct oshmem_group_t *group,
81+
void *target,
82+
const void *source,
83+
ptrdiff_t dst, ptrdiff_t sst,
84+
size_t nelems,
85+
size_t element_size,
86+
long *pSync,
87+
int alg);
8088

8189
static inline unsigned int scoll_log2(unsigned long val)
8290
{
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 2016 Mellanox Technologies, Inc.
3+
* All rights reserved.
4+
* $COPYRIGHT$
5+
*
6+
* Additional copyrights may follow
7+
*
8+
* $HEADER$
9+
*/
10+
11+
#include "oshmem_config.h"
12+
#include <stdio.h>
13+
#include <stdlib.h>
14+
15+
#include "oshmem/constants.h"
16+
#include "oshmem/op/op.h"
17+
#include "oshmem/mca/spml/spml.h"
18+
#include "oshmem/mca/scoll/scoll.h"
19+
#include "oshmem/mca/scoll/base/base.h"
20+
#include "scoll_basic.h"
21+
22+
static int _algorithm_simple(struct oshmem_group_t *group,
23+
void *target,
24+
const void *source,
25+
ptrdiff_t dst, ptrdiff_t sst,
26+
size_t nelems,
27+
size_t element_size,
28+
long *pSync);
29+
30+
int mca_scoll_basic_alltoall(struct oshmem_group_t *group,
31+
void *target,
32+
const void *source,
33+
ptrdiff_t dst, ptrdiff_t sst,
34+
size_t nelems,
35+
size_t element_size,
36+
long *pSync,
37+
int alg)
38+
{
39+
int rc = OSHMEM_SUCCESS;
40+
41+
/* Arguments validation */
42+
if (!group) {
43+
SCOLL_ERROR("Active set (group) of PE is not defined");
44+
rc = OSHMEM_ERR_BAD_PARAM;
45+
}
46+
47+
/* Check if this PE is part of the group */
48+
if ((rc == OSHMEM_SUCCESS) && oshmem_proc_group_is_member(group)) {
49+
int i = 0;
50+
51+
if (pSync) {
52+
rc = _algorithm_simple(group,
53+
target,
54+
source,
55+
dst,
56+
sst,
57+
nelems,
58+
element_size,
59+
pSync);
60+
} else {
61+
SCOLL_ERROR("Incorrect argument pSync");
62+
rc = OSHMEM_ERR_BAD_PARAM;
63+
}
64+
65+
/* Restore initial values */
66+
SCOLL_VERBOSE(12,
67+
"PE#%d Restore special synchronization array",
68+
group->my_pe);
69+
for (i = 0; pSync && (i < _SHMEM_ALLTOALL_SYNC_SIZE); i++) {
70+
pSync[i] = _SHMEM_SYNC_VALUE;
71+
}
72+
}
73+
74+
return rc;
75+
}
76+
77+
static int _algorithm_simple(struct oshmem_group_t *group,
78+
void *target,
79+
const void *source,
80+
ptrdiff_t tst, ptrdiff_t sst,
81+
size_t nelems,
82+
size_t element_size,
83+
long *pSync)
84+
{
85+
int rc = OSHMEM_SUCCESS;
86+
int pe_cur;
87+
int i;
88+
int j;
89+
int k;
90+
91+
SCOLL_VERBOSE(14,
92+
"[#%d] send data to all PE in the group",
93+
group->my_pe);
94+
j = oshmem_proc_group_find_id(group, group->my_pe);
95+
for (i = 0; i < group->proc_count; i++) {
96+
/* index permutation for better distribution of traffic */
97+
k = (((j)+(i))%(group->proc_count));
98+
pe_cur = oshmem_proc_pe(group->proc_array[k]);
99+
rc = MCA_SPML_CALL(put(
100+
(void *)((char *)target + j * tst * nelems * element_size),
101+
nelems * element_size,
102+
(void *)((char *)source + i * sst * nelems * element_size),
103+
pe_cur));
104+
if (OSHMEM_SUCCESS != rc) {
105+
break;
106+
}
107+
}
108+
109+
/* Wait for operation completion */
110+
if (rc == OSHMEM_SUCCESS) {
111+
SCOLL_VERBOSE(14, "[#%d] Wait for operation completion", group->my_pe);
112+
rc = BARRIER_FUNC(group,
113+
(pSync + 1),
114+
SCOLL_DEFAULT_ALG);
115+
}
116+
117+
return rc;
118+
}

oshmem/mca/scoll/basic/scoll_basic_module.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013 Mellanox Technologies, Inc.
2+
* Copyright (c) 2013-2016 Mellanox Technologies, Inc.
33
* All rights reserved.
44
* $COPYRIGHT$
55
*
@@ -52,9 +52,10 @@ mca_scoll_basic_query(struct oshmem_group_t *group, int *priority)
5252
module->super.scoll_broadcast = mca_scoll_basic_broadcast;
5353
module->super.scoll_collect = mca_scoll_basic_collect;
5454
module->super.scoll_reduce = mca_scoll_basic_reduce;
55+
module->super.scoll_alltoall = mca_scoll_basic_alltoall;
5556
module->super.scoll_module_enable = mca_scoll_basic_enable;
5657
return &(module->super);
5758
}
5859

59-
return NULL ;
60+
return NULL;
6061
}

oshmem/mca/scoll/fca/scoll_fca.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ struct mca_scoll_fca_module_t {
9393
mca_scoll_base_module_t *previous_collect_module;
9494
mca_scoll_base_module_reduce_fn_t previous_reduce;
9595
mca_scoll_base_module_t *previous_reduce_module;
96+
mca_scoll_base_module_alltoall_fn_t previous_alltoall;
97+
mca_scoll_base_module_t *previous_alltoall_module;
9698
};
9799
typedef struct mca_scoll_fca_module_t mca_scoll_fca_module_t;
98100
OBJ_CLASS_DECLARATION(mca_scoll_fca_module_t);

oshmem/mca/scoll/fca/scoll_fca_module.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ static int _save_coll_handlers(mca_scoll_fca_module_t *fca_module)
391391
FCA_SAVE_PREV_SCOLL_API(broadcast);
392392
FCA_SAVE_PREV_SCOLL_API(collect);
393393
FCA_SAVE_PREV_SCOLL_API(reduce);
394+
FCA_SAVE_PREV_SCOLL_API(alltoall);
394395

395396
return OSHMEM_SUCCESS;
396397
}
@@ -450,6 +451,7 @@ static void mca_scoll_fca_module_clear(mca_scoll_fca_module_t *fca_module)
450451
fca_module->previous_broadcast = NULL;
451452
fca_module->previous_collect = NULL;
452453
fca_module->previous_reduce = NULL;
454+
fca_module->previous_alltoall = NULL;
453455
}
454456

455457
static void mca_scoll_fca_module_construct(mca_scoll_fca_module_t *fca_module)
@@ -465,6 +467,7 @@ static void mca_scoll_fca_module_destruct(mca_scoll_fca_module_t *fca_module)
465467
OBJ_RELEASE(fca_module->previous_broadcast_module);
466468
OBJ_RELEASE(fca_module->previous_collect_module);
467469
OBJ_RELEASE(fca_module->previous_reduce_module);
470+
OBJ_RELEASE(fca_module->previous_alltoall_module);
468471
if (fca_module->fca_comm)
469472
_destroy_fca_comm(fca_module);
470473
free(fca_module->local_ranks);
@@ -541,6 +544,7 @@ mca_scoll_fca_comm_query(struct oshmem_group_t *comm, int *priority)
541544
fca_module->super.scoll_broadcast =
542545
mca_scoll_fca_component.fca_enable_bcast ? mca_scoll_fca_broadcast :
543546
NULL;
547+
fca_module->super.scoll_alltoall = NULL;
544548

545549
*priority = mca_scoll_fca_component.fca_priority;
546550
module = &fca_module->super;

oshmem/mca/scoll/mpi/scoll_mpi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ struct mca_scoll_mpi_module_t {
6969
mca_scoll_base_module_t *previous_barrier_module;
7070
mca_scoll_base_module_collect_fn_t previous_collect;
7171
mca_scoll_base_module_t *previous_collect_module;
72+
mca_scoll_base_module_alltoall_fn_t previous_alltoall;
73+
mca_scoll_base_module_t *previous_alltoall_module;
7274
};
7375
typedef struct mca_scoll_mpi_module_t mca_scoll_mpi_module_t;
7476

0 commit comments

Comments
 (0)