Skip to content

Commit 4384432

Browse files
committed
WIP: add opal types for atomic variables
This is a work in progress to move the entire codebase to using opal types for atomic variables instead of just marking them as volatile. This is the first step towards moving to C11 atomics as those need to use atomic_ or _Atomic types. Signed-off-by: Nathan Hjelm <[email protected]>
1 parent c87a3df commit 4384432

File tree

108 files changed

+622
-563
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+622
-563
lines changed

ompi/communicator/comm_request.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22
/*
3-
* Copyright (c) 2013-2016 Los Alamos National Security, LLC. All rights
3+
* Copyright (c) 2013-2018 Los Alamos National Security, LLC. All rights
44
* reseved.
55
* Copyright (c) 2015 Research Organization for Information Science
66
* and Technology (RIST). All rights reserved.
@@ -99,7 +99,7 @@ int ompi_comm_request_schedule_append (ompi_comm_request_t *request, ompi_comm_r
9999
static int ompi_comm_request_progress (void)
100100
{
101101
ompi_comm_request_t *request, *next;
102-
static int32_t progressing = 0;
102+
static opal_atomic_int32_t progressing = 0;
103103

104104
/* don't allow re-entry */
105105
if (opal_atomic_swap_32 (&progressing, 1)) {

ompi/datatype/ompi_datatype.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct ompi_datatype_t {
7575
struct opal_hash_table_t *d_keyhash; /**< Attribute fields */
7676

7777
void* args; /**< Data description for the user */
78-
void* packed_description; /**< Packed description of the datatype */
78+
opal_atomic_intptr_t packed_description; /**< Packed description of the datatype */
7979
uint64_t pml_data; /**< PML-specific information */
8080
/* --- cacheline 6 boundary (384 bytes) --- */
8181
char name[MPI_MAX_OBJECT_NAME];/**< Externally visible name */

ompi/datatype/ompi_datatype_args.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ __ompi_datatype_create_from_args( int32_t* i, ptrdiff_t * a,
4545
ompi_datatype_t** d, int32_t type );
4646

4747
typedef struct __dt_args {
48-
int32_t ref_count;
48+
opal_atomic_int32_t ref_count;
4949
int32_t create_type;
5050
size_t total_pack_size;
5151
int32_t ci;
@@ -104,7 +104,7 @@ typedef struct __dt_args {
104104
pArgs->total_pack_size = (4 + (IC) + (DC)) * sizeof(int) + \
105105
(AC) * sizeof(ptrdiff_t); \
106106
(PDATA)->args = (void*)pArgs; \
107-
(PDATA)->packed_description = NULL; \
107+
(PDATA)->packed_description = 0; \
108108
} while(0)
109109

110110

@@ -483,12 +483,12 @@ int ompi_datatype_get_pack_description( ompi_datatype_t* datatype,
483483
{
484484
ompi_datatype_args_t* args = (ompi_datatype_args_t*)datatype->args;
485485
int next_index = OMPI_DATATYPE_MAX_PREDEFINED;
486-
void *packed_description = datatype->packed_description;
486+
void *packed_description = (void *) datatype->packed_description;
487487
void* recursive_buffer;
488488

489489
if (NULL == packed_description) {
490490
void *_tmp_ptr = NULL;
491-
if (opal_atomic_compare_exchange_strong_ptr (&datatype->packed_description, (void *) &_tmp_ptr, (void *) 1)) {
491+
if (opal_atomic_compare_exchange_strong_ptr (&datatype->packed_description, (intptr_t *) &_tmp_ptr, 1)) {
492492
if( ompi_datatype_is_predefined(datatype) ) {
493493
packed_description = malloc(2 * sizeof(int));
494494
} else if( NULL == args ) {
@@ -510,22 +510,22 @@ int ompi_datatype_get_pack_description( ompi_datatype_t* datatype,
510510
}
511511

512512
opal_atomic_wmb ();
513-
datatype->packed_description = packed_description;
513+
datatype->packed_description = (intptr_t) packed_description;
514514
} else {
515515
/* another thread beat us to it */
516-
packed_description = datatype->packed_description;
516+
packed_description = (void *) datatype->packed_description;
517517
}
518518
}
519519

520520
if ((void *) 1 == packed_description) {
521521
struct timespec interval = {.tv_sec = 0, .tv_nsec = 1000};
522522

523523
/* wait until the packed description is updated */
524-
while ((void *) 1 == datatype->packed_description) {
524+
while (1 == datatype->packed_description) {
525525
nanosleep (&interval, NULL);
526526
}
527527

528-
packed_description = datatype->packed_description;
528+
packed_description = (void *) datatype->packed_description;
529529
}
530530

531531
*packed_buffer = (const void *) packed_description;
@@ -534,7 +534,7 @@ int ompi_datatype_get_pack_description( ompi_datatype_t* datatype,
534534

535535
size_t ompi_datatype_pack_description_length( ompi_datatype_t* datatype )
536536
{
537-
void *packed_description = datatype->packed_description;
537+
void *packed_description = (void *) datatype->packed_description;
538538

539539
if( ompi_datatype_is_predefined(datatype) ) {
540540
return 2 * sizeof(int);

ompi/datatype/ompi_datatype_create.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void __ompi_datatype_allocate( ompi_datatype_t* datatype )
3636
datatype->id = -1;
3737
datatype->d_keyhash = NULL;
3838
datatype->name[0] = '\0';
39-
datatype->packed_description = NULL;
39+
datatype->packed_description = 0;
4040
datatype->pml_data = 0;
4141
}
4242

@@ -46,10 +46,10 @@ static void __ompi_datatype_release(ompi_datatype_t * datatype)
4646
ompi_datatype_release_args( datatype );
4747
datatype->args = NULL;
4848
}
49-
if( NULL != datatype->packed_description ) {
50-
free( datatype->packed_description );
51-
datatype->packed_description = NULL;
52-
}
49+
50+
free ((void *) datatype->packed_description );
51+
datatype->packed_description = 0;
52+
5353
if( datatype->d_f_to_c_index >= 0 ) {
5454
opal_pointer_array_set_item( &ompi_datatype_f_to_c_table, datatype->d_f_to_c_index, NULL );
5555
datatype->d_f_to_c_index = -1;

ompi/datatype/ompi_datatype_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ extern const ompi_datatype_t* ompi_datatype_basicDatatypes[OMPI_DATATYPE_MPI_MAX
406406
.d_f_to_c_index = -1, \
407407
.d_keyhash = NULL, \
408408
.args = NULL, \
409-
.packed_description = NULL, \
409+
.packed_description = 0, \
410410
.name = "MPI_" # NAME
411411

412412
#define OMPI_DATATYPE_INITIALIZER_UNAVAILABLE(FLAGS) \

ompi/datatype/ompi_datatype_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ opal_pointer_array_t ompi_datatype_f_to_c_table = {{0}};
383383
(PDST)->super.desc = (PSRC)->super.desc; \
384384
(PDST)->super.opt_desc = (PSRC)->super.opt_desc; \
385385
(PDST)->packed_description = (PSRC)->packed_description; \
386-
(PSRC)->packed_description = NULL; \
386+
(PSRC)->packed_description = 0; \
387387
/* transfer the ptypes */ \
388388
(PDST)->super.ptypes = (PSRC)->super.ptypes; \
389389
(PSRC)->super.ptypes = NULL; \

ompi/group/group.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ static inline struct ompi_proc_t *ompi_group_dense_lookup (ompi_group_t *group,
356356
ompi_proc_t *real_proc =
357357
(ompi_proc_t *) ompi_proc_for_name (ompi_proc_sentinel_to_name ((uintptr_t) proc));
358358

359-
if (opal_atomic_compare_exchange_strong_ptr (group->grp_proc_pointers + peer_id, &proc, real_proc)) {
359+
if (opal_atomic_compare_exchange_strong_ptr ((opal_atomic_intptr_t *)(group->grp_proc_pointers + peer_id),
360+
(intptr_t *) &proc, (intptr_t) real_proc)) {
360361
OBJ_RETAIN(real_proc);
361362
}
362363

ompi/mca/coll/libnbc/coll_libnbc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct ompi_coll_libnbc_component_t {
7575
mca_coll_base_component_2_0_0_t super;
7676
opal_free_list_t requests;
7777
opal_list_t active_requests;
78-
int32_t active_comms;
78+
opal_atomic_int32_t active_comms;
7979
opal_mutex_t lock; /* protect access to the active_requests list */
8080
};
8181
typedef struct ompi_coll_libnbc_component_t ompi_coll_libnbc_component_t;

ompi/mca/coll/monitoring/coll_monitoring.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct mca_coll_monitoring_module_t {
3636
mca_coll_base_module_t super;
3737
mca_coll_base_comm_coll_t real;
3838
mca_monitoring_coll_data_t*data;
39-
int32_t is_initialized;
39+
opal_atomic_int32_t is_initialized;
4040
};
4141
typedef struct mca_coll_monitoring_module_t mca_coll_monitoring_module_t;
4242
OMPI_DECLSPEC OBJ_CLASS_DECLARATION(mca_coll_monitoring_module_t);

ompi/mca/coll/portals4/coll_portals4.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
12
/*
23
* Copyright (c) 2013-2015 Sandia National Laboratories. All rights reserved.
3-
* Copyright (c) 2015 Los Alamos National Security, LLC. All rights
4+
* Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights
45
* reserved.
56
* Copyright (c) 2015 Bull SAS. All rights reserved.
67
* Copyright (c) 2015 Research Organization for Information Science
@@ -91,7 +92,7 @@ typedef struct ompi_coll_portals4_tree_t {
9192

9293
struct mca_coll_portals4_module_t {
9394
mca_coll_base_module_t super;
94-
size_t coll_count;
95+
opal_atomic_size_t coll_count;
9596

9697
/* record handlers dedicated to fallback if offloaded operations are not supported */
9798
mca_coll_base_module_reduce_fn_t previous_reduce;

ompi/mca/coll/sm/coll_sm.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ BEGIN_C_DECLS
114114
typedef struct mca_coll_sm_in_use_flag_t {
115115
/** Number of processes currently using this set of
116116
segments */
117-
volatile uint32_t mcsiuf_num_procs_using;
117+
opal_atomic_uint32_t mcsiuf_num_procs_using;
118118
/** Must match data->mcb_count */
119119
volatile uint32_t mcsiuf_operation_count;
120120
} mca_coll_sm_in_use_flag_t;
@@ -152,7 +152,7 @@ BEGIN_C_DECLS
152152
/** Pointer to my parent's barrier control pages (will be NULL
153153
for communicator rank 0; odd index pages are "in", even
154154
index pages are "out") */
155-
uint32_t *mcb_barrier_control_parent;
155+
opal_atomic_uint32_t *mcb_barrier_control_parent;
156156

157157
/** Pointers to my childrens' barrier control pages (they're
158158
contiguous in memory, so we only point to the base -- the

ompi/mca/coll/sm/coll_sm_barrier.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ int mca_coll_sm_barrier_intra(struct ompi_communicator_t *comm,
5656
int rank, buffer_set;
5757
mca_coll_sm_comm_t *data;
5858
uint32_t i, num_children;
59-
volatile uint32_t *me_in, *me_out, *parent, *children = NULL;
59+
volatile uint32_t *me_in, *me_out, *children = NULL;
60+
opal_atomic_uint32_t *parent;
6061
int uint_control_size;
6162
mca_coll_sm_module_t *sm_module = (mca_coll_sm_module_t*) module;
6263

ompi/mca/coll/sm/coll_sm_module.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ int ompi_coll_sm_lazy_enable(mca_coll_base_module_t *module,
372372
data->mcb_barrier_control_me = (uint32_t*)
373373
(base + (rank * control_size * num_barrier_buffers * 2));
374374
if (data->mcb_tree[rank].mcstn_parent) {
375-
data->mcb_barrier_control_parent = (uint32_t*)
375+
data->mcb_barrier_control_parent = (opal_atomic_uint32_t*)
376376
(base +
377377
(data->mcb_tree[rank].mcstn_parent->mcstn_id * control_size *
378378
num_barrier_buffers * 2));

ompi/mca/common/monitoring/common_monitoring.c

+17-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Copyright (c) 2015 Bull SAS. All rights reserved.
88
* Copyright (c) 2016-2017 Research Organization for Information Science
99
* and Technology (RIST). All rights reserved.
10-
* Copyright (c) 2017 Los Alamos National Security, LLC. All rights
10+
* Copyright (c) 2017-2018 Los Alamos National Security, LLC. All rights
1111
* reserved.
1212
* $COPYRIGHT$
1313
*
@@ -34,7 +34,7 @@
3434

3535
/*** Monitoring specific variables ***/
3636
/* Keep tracks of how many components are currently using the common part */
37-
static int32_t mca_common_monitoring_hold = 0;
37+
static opal_atomic_int32_t mca_common_monitoring_hold = 0;
3838
/* Output parameters */
3939
int mca_common_monitoring_output_stream_id = -1;
4040
static opal_output_stream_t mca_common_monitoring_output_stream_obj = {
@@ -61,18 +61,18 @@ static char* mca_common_monitoring_initial_filename = "";
6161
static char* mca_common_monitoring_current_filename = NULL;
6262

6363
/* array for stroring monitoring data*/
64-
static size_t* pml_data = NULL;
65-
static size_t* pml_count = NULL;
66-
static size_t* filtered_pml_data = NULL;
67-
static size_t* filtered_pml_count = NULL;
68-
static size_t* osc_data_s = NULL;
69-
static size_t* osc_count_s = NULL;
70-
static size_t* osc_data_r = NULL;
71-
static size_t* osc_count_r = NULL;
72-
static size_t* coll_data = NULL;
73-
static size_t* coll_count = NULL;
74-
75-
static size_t* size_histogram = NULL;
64+
static opal_atomic_size_t* pml_data = NULL;
65+
static opal_atomic_size_t* pml_count = NULL;
66+
static opal_atomic_size_t* filtered_pml_data = NULL;
67+
static opal_atomic_size_t* filtered_pml_count = NULL;
68+
static opal_atomic_size_t* osc_data_s = NULL;
69+
static opal_atomic_size_t* osc_count_s = NULL;
70+
static opal_atomic_size_t* osc_data_r = NULL;
71+
static opal_atomic_size_t* osc_count_r = NULL;
72+
static opal_atomic_size_t* coll_data = NULL;
73+
static opal_atomic_size_t* coll_count = NULL;
74+
75+
static opal_atomic_size_t* size_histogram = NULL;
7676
static const int max_size_histogram = 66;
7777
static double log10_2 = 0.;
7878

@@ -241,7 +241,7 @@ void mca_common_monitoring_finalize( void )
241241
opal_output_close(mca_common_monitoring_output_stream_id);
242242
free(mca_common_monitoring_output_stream_obj.lds_prefix);
243243
/* Free internal data structure */
244-
free(pml_data); /* a single allocation */
244+
free((void *) pml_data); /* a single allocation */
245245
opal_hash_table_remove_all( common_monitoring_translation_ht );
246246
OBJ_RELEASE(common_monitoring_translation_ht);
247247
mca_common_monitoring_coll_finalize();
@@ -446,7 +446,7 @@ int mca_common_monitoring_add_procs(struct ompi_proc_t **procs,
446446

447447
if( NULL == pml_data ) {
448448
int array_size = (10 + max_size_histogram) * nprocs_world;
449-
pml_data = (size_t*)calloc(array_size, sizeof(size_t));
449+
pml_data = (opal_atomic_size_t*)calloc(array_size, sizeof(size_t));
450450
pml_count = pml_data + nprocs_world;
451451
filtered_pml_data = pml_count + nprocs_world;
452452
filtered_pml_count = filtered_pml_data + nprocs_world;
@@ -493,7 +493,7 @@ int mca_common_monitoring_add_procs(struct ompi_proc_t **procs,
493493
static void mca_common_monitoring_reset( void )
494494
{
495495
int array_size = (10 + max_size_histogram) * nprocs_world;
496-
memset(pml_data, 0, array_size * sizeof(size_t));
496+
memset((void *) pml_data, 0, array_size * sizeof(size_t));
497497
mca_common_monitoring_coll_reset();
498498
}
499499

ompi/mca/common/monitoring/common_monitoring_coll.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ struct mca_monitoring_coll_data_t {
3030
int world_rank;
3131
int is_released;
3232
ompi_communicator_t*p_comm;
33-
size_t o2a_count;
34-
size_t o2a_size;
35-
size_t a2o_count;
36-
size_t a2o_size;
37-
size_t a2a_count;
38-
size_t a2a_size;
33+
opal_atomic_size_t o2a_count;
34+
opal_atomic_size_t o2a_size;
35+
opal_atomic_size_t a2o_count;
36+
opal_atomic_size_t a2o_size;
37+
opal_atomic_size_t a2a_count;
38+
opal_atomic_size_t a2a_size;
3939
};
4040

4141
/* Collectives operation monitoring */

ompi/mca/common/ompio/common_ompio_cuda.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static opal_mutex_t mca_common_ompio_cuda_mutex; /* lock for thread saf
3434
static mca_allocator_base_component_t* mca_common_ompio_allocator_component=NULL;
3535
static mca_allocator_base_module_t* mca_common_ompio_allocator=NULL;
3636

37-
static int32_t mca_common_ompio_cuda_init = 0;
37+
static opal_atomic_int32_t mca_common_ompio_cuda_init = 0;
3838
static int32_t mca_common_ompio_pagesize=4096;
3939
static void* mca_common_ompio_cuda_alloc_seg ( void *ctx, size_t *size );
4040
static void mca_common_ompio_cuda_free_seg ( void *ctx, void *buf );

ompi/mca/mtl/portals4/mtl_portals4.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ struct mca_mtl_portals4_module_t {
115115
opal_mutex_t short_block_mutex;
116116

117117
/** number of send-side operations started */
118-
uint64_t opcount;
118+
opal_atomic_uint64_t opcount;
119119

120120
#if OPAL_ENABLE_DEBUG
121121
/** number of receive-side operations started. Used only for
122122
debugging */
123-
uint64_t recv_opcount;
123+
opal_atomic_uint64_t recv_opcount;
124124
#endif
125125

126126
#if OMPI_MTL_PORTALS4_FLOW_CONTROL

ompi/mca/mtl/portals4/mtl_portals4_flowctl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
22
/*
33
* Copyright (c) 2012 Sandia National Laboratories. All rights reserved.
4-
* Copyright (c) 2015-2017 Los Alamos National Security, LLC. All rights
4+
* Copyright (c) 2015-2018 Los Alamos National Security, LLC. All rights
55
* reserved.
66
* $COPYRIGHT$
77
*

ompi/mca/mtl/portals4/mtl_portals4_flowctl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ OBJ_CLASS_DECLARATION(ompi_mtl_portals4_pending_request_t);
3636
struct ompi_mtl_portals4_flowctl_t {
3737
int32_t flowctl_active;
3838

39-
int32_t send_slots;
39+
opal_atomic_int32_t send_slots;
4040
int32_t max_send_slots;
4141
opal_list_t pending_sends;
4242
opal_free_list_t pending_fl;
@@ -46,7 +46,7 @@ struct ompi_mtl_portals4_flowctl_t {
4646

4747
/** Flow control epoch counter. Triggered events should be
4848
based on epoch counter. */
49-
int64_t epoch_counter;
49+
opal_atomic_int64_t epoch_counter;
5050

5151
/** Flow control trigger CT. Only has meaning at root. */
5252
ptl_handle_ct_t trigger_ct_h;

ompi/mca/mtl/portals4/mtl_portals4_request.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ struct ompi_mtl_portals4_isend_request_t {
5454
struct ompi_mtl_portals4_pending_request_t *pending;
5555
#endif
5656
ptl_size_t length;
57-
int32_t pending_get;
58-
uint32_t event_count;
57+
opal_atomic_int32_t pending_get;
58+
opal_atomic_uint32_t event_count;
5959
};
6060
typedef struct ompi_mtl_portals4_isend_request_t ompi_mtl_portals4_isend_request_t;
6161

@@ -76,7 +76,7 @@ struct ompi_mtl_portals4_recv_request_t {
7676
void *delivery_ptr;
7777
size_t delivery_len;
7878
volatile bool req_started;
79-
int32_t pending_reply;
79+
opal_atomic_int32_t pending_reply;
8080
#if OPAL_ENABLE_DEBUG
8181
uint64_t opcount;
8282
ptl_hdr_data_t hdr_data;

ompi/mca/osc/monitoring/osc_monitoring_module.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
OSC_MONITORING_SET_TEMPLATE_FCT_NAME(template) (ompi_osc_base_module_t*module) \
5151
{ \
5252
/* Define the ompi_osc_monitoring_module_## template ##_init_done variable */ \
53-
static int32_t init_done = 0; \
53+
opal_atomic_int32_t init_done = 0; \
5454
/* Define and set the ompi_osc_monitoring_## template \
5555
* ##_template variable. The functions recorded here are \
5656
* linked to the original functions of the original \

0 commit comments

Comments
 (0)