Skip to content

Commit 2ae0f3b

Browse files
committed
Merge pull request open-mpi#599 from hjelmn/v2.x_acc_ops
ompi/win: save value of accumulate_ops info key on window
2 parents 88141b3 + 38c0de1 commit 2ae0f3b

File tree

5 files changed

+95
-13
lines changed

5 files changed

+95
-13
lines changed

ompi/info/info.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,22 @@ int ompi_info_set (ompi_info_t *info, const char *key, const char *value)
272272
}
273273

274274

275+
int ompi_info_set_value_enum (ompi_info_t *info, const char *key, int value,
276+
mca_base_var_enum_t *var_enum)
277+
{
278+
char *string_value;
279+
int ret;
280+
281+
ret = var_enum->string_from_value (var_enum, value, &string_value);
282+
if (OPAL_SUCCESS != ret) {
283+
return ret;
284+
}
285+
286+
return ompi_info_set (info, key, string_value);
287+
}
288+
289+
290+
275291
/*
276292
* Free an info handle and all of its keys and values.
277293
*/

ompi/info/info.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int ompi_info_finalize(void);
151151
*/
152152
int ompi_info_dup (ompi_info_t *info, ompi_info_t **newinfo);
153153

154-
/*
154+
/**
155155
* Set a new key,value pair on info.
156156
*
157157
* @param info pointer to ompi_info_t object
@@ -163,6 +163,21 @@ int ompi_info_dup (ompi_info_t *info, ompi_info_t **newinfo);
163163
*/
164164
OMPI_DECLSPEC int ompi_info_set (ompi_info_t *info, const char *key, const char *value);
165165

166+
/**
167+
* Set a new key,value pair from a variable enumerator.
168+
*
169+
* @param info pointer to ompi_info_t object
170+
* @param key pointer to the new key object
171+
* @param value integer value of the info key (must be valid in var_enum)
172+
* @param var_enum variable enumerator
173+
*
174+
* @retval MPI_SUCCESS upon success
175+
* @retval MPI_ERR_NO_MEM if out of memory
176+
* @retval OPAL_ERR_VALUE_OUT_OF_BOUNDS if the value is not valid in the enumerator
177+
*/
178+
OMPI_DECLSPEC int ompi_info_set_value_enum (ompi_info_t *info, const char *key, int value,
179+
mca_base_var_enum_t *var_enum);
180+
166181
/**
167182
* ompi_info_free - Free an 'MPI_Info' object.
168183
*

ompi/mpi/c/win_get_info.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ int MPI_Win_get_info(MPI_Win win, MPI_Info *info_used)
5858
_win_info_set (*info_used, "no_locks", win->w_flags & OMPI_WIN_NO_LOCKS);
5959
_win_info_set (*info_used, "same_size", win->w_flags & OMPI_WIN_SAME_SIZE);
6060
_win_info_set (*info_used, "same_disp_unit", win->w_flags & OMPI_WIN_SAME_DISP);
61+
ompi_info_set_value_enum (*info_used, "accumulate_ops", win->w_acc_ops, ompi_win_accumulate_ops);
6162
}
6263

6364
OMPI_ERRHANDLER_RETURN(ret, win, ret, FUNC_NAME);

ompi/win/win.c

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ opal_pointer_array_t ompi_mpi_windows = {{0}};
4444

4545
ompi_predefined_win_t ompi_mpi_win_null = {{{0}}};
4646
ompi_predefined_win_t *ompi_mpi_win_null_addr = &ompi_mpi_win_null;
47+
mca_base_var_enum_t *ompi_win_accumulate_ops = NULL;
48+
49+
static mca_base_var_enum_value_t accumulate_ops_values[] = {
50+
{.value = OMPI_WIN_ACCUMULATE_OPS_SAME_OP_NO_OP, .string = "same_op_no_op",},
51+
{.value = OMPI_WIN_ACCUMULATE_OPS_SAME_OP, .string = "same_op",},
52+
{.value = -1, .string = NULL},
53+
};
4754

4855
static void ompi_win_construct(ompi_win_t *win);
4956
static void ompi_win_destruct(ompi_win_t *win);
@@ -54,6 +61,10 @@ OBJ_CLASS_INSTANCE(ompi_win_t, opal_object_t,
5461
int
5562
ompi_win_init(void)
5663
{
64+
int ret;
65+
66+
assert (sizeof (ompi_predefined_win_t) >= sizeof (ompi_win_t));
67+
5768
/* setup window Fortran array */
5869
OBJ_CONSTRUCT(&ompi_mpi_windows, opal_pointer_array_t);
5970
if( OPAL_SUCCESS != opal_pointer_array_init(&ompi_mpi_windows, 0,
@@ -69,6 +80,11 @@ ompi_win_init(void)
6980
ompi_win_set_name(&ompi_mpi_win_null.win, "MPI_WIN_NULL");
7081
opal_pointer_array_set_item(&ompi_mpi_windows, 0, &ompi_mpi_win_null.win);
7182

83+
ret = mca_base_var_enum_create ("accumulate_ops", accumulate_ops_values, &ompi_win_accumulate_ops);
84+
if (OPAL_SUCCESS != ret) {
85+
return ret;
86+
}
87+
7288
return OMPI_SUCCESS;
7389
}
7490

@@ -78,27 +94,42 @@ ompi_win_finalize(void)
7894
{
7995
OBJ_DESTRUCT(&ompi_mpi_win_null.win);
8096
OBJ_DESTRUCT(&ompi_mpi_windows);
97+
OBJ_RELEASE(ompi_win_accumulate_ops);
8198

8299
return OMPI_SUCCESS;
83100
}
84101

85-
static ompi_win_t *
86-
alloc_window(struct ompi_communicator_t *comm)
102+
static int alloc_window(struct ompi_communicator_t *comm, ompi_info_t *info, ompi_win_t **win_out)
87103
{
88104
ompi_win_t *win;
89105
ompi_group_t *group;
106+
int acc_ops, flag, ret;
90107

91108
/* create the object */
92109
win = OBJ_NEW(ompi_win_t);
93-
if (NULL == win) return NULL;
110+
if (NULL == win) {
111+
return OMPI_ERR_OUT_OF_RESOURCE;
112+
}
113+
114+
ret = ompi_info_get_value_enum (info, "accumulate_ops", &acc_ops,
115+
OMPI_WIN_ACCUMULATE_OPS_SAME_OP_NO_OP,
116+
ompi_win_accumulate_ops, &flag);
117+
if (OMPI_SUCCESS != ret) {
118+
OBJ_RELEASE(win);
119+
return ret;
120+
}
121+
122+
win->w_acc_ops = acc_ops;
94123

95124
/* setup data that is independent of osc component */
96125
group = comm->c_local_group;
97126
OBJ_RETAIN(group);
98127
ompi_group_increment_proc_count(group);
99128
win->w_group = group;
100129

101-
return win;
130+
*win_out = win;
131+
132+
return OMPI_SUCCESS;
102133
}
103134

104135
static int
@@ -148,8 +179,10 @@ ompi_win_create(void *base, size_t size,
148179
int model;
149180
int ret;
150181

151-
win = alloc_window(comm);
152-
if (NULL == win) return OMPI_ERR_OUT_OF_RESOURCE;
182+
ret = alloc_window (comm, info, &win);
183+
if (OMPI_SUCCESS != ret) {
184+
return ret;
185+
}
153186

154187
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, info, MPI_WIN_FLAVOR_CREATE, &model);
155188
if (OMPI_SUCCESS != ret) {
@@ -178,8 +211,10 @@ ompi_win_allocate(size_t size, int disp_unit, ompi_info_t *info,
178211
int ret;
179212
void *base;
180213

181-
win = alloc_window(comm);
182-
if (NULL == win) return OMPI_ERR_OUT_OF_RESOURCE;
214+
ret = alloc_window (comm, info, &win);
215+
if (OMPI_SUCCESS != ret) {
216+
return ret;
217+
}
183218

184219
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, info, MPI_WIN_FLAVOR_ALLOCATE, &model);
185220
if (OMPI_SUCCESS != ret) {
@@ -209,8 +244,10 @@ ompi_win_allocate_shared(size_t size, int disp_unit, ompi_info_t *info,
209244
int ret;
210245
void *base;
211246

212-
win = alloc_window(comm);
213-
if (NULL == win) return OMPI_ERR_OUT_OF_RESOURCE;
247+
ret = alloc_window (comm, info, &win);
248+
if (OMPI_SUCCESS != ret) {
249+
return ret;
250+
}
214251

215252
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, info, MPI_WIN_FLAVOR_SHARED, &model);
216253
if (OMPI_SUCCESS != ret) {
@@ -238,8 +275,10 @@ ompi_win_create_dynamic(ompi_info_t *info, ompi_communicator_t *comm, ompi_win_t
238275
int model;
239276
int ret;
240277

241-
win = alloc_window(comm);
242-
if (NULL == win) return OMPI_ERR_OUT_OF_RESOURCE;
278+
ret = alloc_window (comm, info, &win);
279+
if (OMPI_SUCCESS != ret) {
280+
return ret;
281+
}
243282

244283
ret = ompi_osc_base_select(win, MPI_BOTTOM, 0, 1, comm, info, MPI_WIN_FLAVOR_DYNAMIC, &model);
245284
if (OMPI_SUCCESS != ret) {

ompi/win/win.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ BEGIN_C_DECLS
4444
#define OMPI_WIN_SAME_DISP 0x00000008
4545
#define OMPI_WIN_SAME_SIZE 0x00000010
4646

47+
enum ompi_win_accumulate_ops_t {
48+
OMPI_WIN_ACCUMULATE_OPS_SAME_OP_NO_OP,
49+
OMPI_WIN_ACCUMULATE_OPS_SAME_OP,
50+
};
51+
typedef enum ompi_win_accumulate_ops_t ompi_win_accumulate_ops_t;
52+
53+
OMPI_DECLSPEC extern mca_base_var_enum_t *ompi_win_accumulate_ops;
54+
4755
OMPI_DECLSPEC extern opal_pointer_array_t ompi_mpi_windows;
4856

4957
struct ompi_win_t {
@@ -59,6 +67,9 @@ struct ompi_win_t {
5967
/* Information about the state of the window. */
6068
uint16_t w_flags;
6169

70+
/** Accumulate ops */
71+
ompi_win_accumulate_ops_t w_acc_ops;
72+
6273
/* Attributes */
6374
opal_hash_table_t *w_keyhash;
6475

0 commit comments

Comments
 (0)