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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 2 deletions
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;

0 commit comments

Comments
 (0)