Skip to content

Commit a4572db

Browse files
authored
Merge pull request #1997 from DLR-AMR/feature-shmem_init_error_checking
Feature: shmem init error checking
2 parents 201d1b4 + e5ab1b8 commit a4572db

9 files changed

Lines changed: 45 additions & 19 deletions

File tree

src/t8_cmesh/t8_cmesh_internal/t8_cmesh_commit.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ t8_cmesh_commit_partitioned_new (t8_cmesh_t cmesh, sc_MPI_Comm comm)
241241
/* TODO: reset cmesh */
242242
return;
243243
}
244-
t8_shmem_init (comm);
244+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup. Could not build Cmesh.");
245245
t8_cmesh_set_shmem_type (comm); /* TODO: do we actually need the shared array? */
246246
t8_stash_attribute_sort (cmesh->stash);
247247

src/t8_cmesh/t8_cmesh_internal/t8_cmesh_partition.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ t8_cmesh_gather_treecount_ext (const t8_cmesh_t cmesh, sc_MPI_Comm comm, const i
195195

196196
tree_offset = cmesh->first_tree_shared ? -cmesh->first_tree - 1 : cmesh->first_tree;
197197
if (cmesh->tree_offsets == NULL) {
198-
t8_shmem_init (comm);
198+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup.");
199199
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
200200
/* Only allocate the shmem array, if it is not already allocated */
201201
cmesh->tree_offsets = t8_cmesh_alloc_offsets (cmesh->mpisize, comm);

src/t8_cmesh/t8_cmesh_io/t8_cmesh_save.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ t8_cmesh_load_and_distribute (const char *fileprefix, const int num_files, sc_MP
834834
T8_ASSERT (mpisize >= num_files);
835835

836836
/* Try to set the comm type */
837-
t8_shmem_init (comm);
837+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup. Could not load cmesh.");
838838
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
839839

840840
/* Use cmesh_bcast, if only one process loads the cmesh: */

src/t8_data/t8_shmem.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,18 @@ t8_shmem_array_is_initialized (const t8_shmem_array_t array)
6060
}
6161
#endif
6262

63-
void
63+
int
6464
t8_shmem_init (sc_MPI_Comm comm)
6565
{
66+
#ifndef T8_ENABLE_MPI
67+
// If we do not use MPI, there is nothing to do.
68+
// We only have a single process.
69+
return 1;
70+
#endif
71+
#ifndef SC_ENABLE_MPICOMMSHARED
72+
SC_ABORT ("Trying to use shared memory but SC_ENABLE_MPICOMMSHARED is not set. This should not happen if you use MPI "
73+
"v.3.0 or higher. Maybe related to https://github.com/DLR-AMR/t8code/pull/1996.");
74+
#endif
6675
/* Check whether intranode and internode comms are set
6776
* for the current communicator. */
6877
sc_MPI_Comm intranode;
@@ -73,8 +82,12 @@ t8_shmem_init (sc_MPI_Comm comm)
7382
if (intranode == sc_MPI_COMM_NULL || internode == sc_MPI_COMM_NULL) {
7483
/* The inter/intra comms are not set. We need to set them to
7584
* initialize shared memory usage. */
76-
sc_mpi_comm_get_and_attach (comm);
85+
return sc_mpi_comm_get_and_attach (comm);
7786
}
87+
int intranode_size;
88+
const int mpiret = sc_MPI_Comm_size (intranode, &intranode_size);
89+
SC_CHECK_MPI (mpiret);
90+
return intranode_size;
7891
}
7992

8093
void

src/t8_data/t8_shmem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ T8_EXTERN_C_BEGIN ();
5353
* \note This function needs to be called to enable shared memory usage for a communicator.
5454
* \note Calling this function multiple times with the same communicator is safe and does
5555
* not change the behaviour.
56+
* \return If the intranode communicator cannot be
57+
* obtained, return 0.
58+
* Otherwise return size of intranode communicator.
5659
*/
57-
void
60+
int
5861
t8_shmem_init (sc_MPI_Comm comm);
5962

6063
#if T8_ENABLE_DEBUG

src/t8_forest/t8_forest_partition.cxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ t8_forest_partition_create_offsets (t8_forest_t forest)
146146
t8_debugf ("Building offsets for forest %p\n", (void *) forest);
147147
comm = forest->mpicomm;
148148
/* Set the shmem array type of comm */
149-
t8_shmem_init (comm);
149+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup. Could not partition forest.");
150150
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
151151
/* Initialize the offset array as a shmem array
152152
* holding mpisize+1 many t8_gloidx_t */
@@ -322,7 +322,7 @@ t8_forest_partition_create_first_desc (t8_forest_t forest)
322322

323323
if (forest->global_first_desc == NULL) {
324324
/* Set the shmem array type of comm */
325-
t8_shmem_init (comm);
325+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup. Could not partition forest.");
326326
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
327327
/* Initialize the offset array as a shmem array
328328
* holding mpisize+1 many t8_linearidx_t to store the elements linear ids */
@@ -425,7 +425,7 @@ t8_forest_partition_create_tree_offsets (t8_forest_t forest)
425425

426426
if (forest->tree_offsets == NULL) {
427427
/* Set the shmem array type of comm */
428-
t8_shmem_init (comm);
428+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup. Could not partition forest.");
429429
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
430430
/* Only allocate the shmem array, if it is not already allocated */
431431
t8_shmem_array_init (&forest->tree_offsets, sizeof (t8_gloidx_t), forest->mpisize + 1, comm);
@@ -496,8 +496,9 @@ t8_forest_partition_compute_new_offset (t8_forest_t forest)
496496
const t8_gloidx_t global_num_leaf_elements = forest_from->global_num_leaf_elements;
497497
const t8_weight_fcn_t *weight_fcn = forest->weight_function;
498498

499-
// Initialize the shmem array.
500-
t8_shmem_init (comm);
499+
T8_ASSERT (forest->element_offsets == NULL);
500+
/* Set the shmem array type to comm */
501+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup. Could not partition forest.");
501502
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
502503
t8_shmem_array_init (&forest->element_offsets, sizeof (t8_gloidx_t), mpisize + 1, comm);
503504

src/t8_vtk/t8_with_vtk/t8_vtk_reader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ t8_vtk_partition (t8_cmesh_t cmesh, const int mpirank, const int mpisize, t8_glo
259259
t8_gloidx_t first_tree = 0;
260260
t8_gloidx_t last_tree = 1;
261261
/* Compute the global id of the first tree on each proc. */
262-
t8_shmem_init (comm);
262+
SC_CHECK_ABORT (t8_shmem_init (comm) > 0, "Error in shared memory setup in vtk output.");
263263
t8_shmem_set_type (comm, T8_SHMEM_BEST_TYPE);
264264
t8_shmem_array_t offsets = NULL;
265265
t8_shmem_array_init (&offsets, sizeof (t8_gloidx_t), mpisize + 1, comm);

test/t8_cmesh/t8_gtest_cmesh_set_partition_offsets.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ TEST_P (cmesh_set_partition_offsets_nocommit, test_set_offsets)
116116
* the array corresponds to any valid partition.
117117
* We use the offset_concentrate function to build an offset array for a partition
118118
* that concentrates all trees at one process. */
119-
t8_shmem_init (sc_MPI_COMM_WORLD);
119+
const int intranode_size = t8_shmem_init (sc_MPI_COMM_WORLD);
120+
ASSERT_GT (intranode_size, 0) << "Could not initialize shared memory.";
120121
t8_shmem_array_t shmem_array = t8_cmesh_offset_concentrate (main_process, sc_MPI_COMM_WORLD, inum_trees);
121122

122123
/* Set the partition offsets */
@@ -135,7 +136,9 @@ TEST_P (cmesh_set_partition_offsets_commit, test_set_offsets)
135136
* the array corresponds to any valid partition.
136137
* We use the offset_concentrate function to build an offset array for a partition
137138
* that concentrates all trees at one process. */
138-
t8_shmem_init (comm);
139+
const int intranode_size = t8_shmem_init (comm);
140+
ASSERT_GT (intranode_size, 0) << "Could not initialize shared memory.";
141+
139142
t8_shmem_array_t shmem_array = t8_cmesh_offset_concentrate (main_process, comm, inum_trees);
140143

141144
/* Set the partition offsets */

test/t8_data/t8_gtest_shmem.cxx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ TEST_P (shmem, test_shmem_init_finalize)
5858
int mpiret;
5959

6060
/* setup shared memory usage */
61-
t8_shmem_init (comm);
61+
const int intrasize_from_init = t8_shmem_init (comm);
62+
ASSERT_GT (intrasize_from_init, 0) << "Error in t8_shmem_init. No intranode communicator set.";
6263

6364
/* Get intranode and internode comm */
6465
sc_mpi_comm_get_node_comms (comm, &intranode, &internode);
@@ -113,7 +114,9 @@ TEST_P (shmem, test_sc_shmem_alloc)
113114
t8_debugf ("Checking shared memory type %s.\n", sc_shmem_type_to_string[shmem_type]);
114115

115116
/* setup shared memory usage */
116-
t8_shmem_init (comm);
117+
const int intranode_size = t8_shmem_init (comm);
118+
ASSERT_GT (intranode_size, 0) << "Could not initialize shared memory.";
119+
117120
t8_shmem_set_type (comm, shmem_type);
118121

119122
#if T8_ENABLE_MPI
@@ -196,7 +199,8 @@ TEST_P (shmem, test_shmem_array_allgatherv)
196199
const sc_shmem_type_t shmem_type = (sc_shmem_type_t) shmem_type_int;
197200

198201
/* setup shared memory usage */
199-
t8_shmem_init (comm);
202+
const int intranode_size = t8_shmem_init (comm);
203+
ASSERT_GT (intranode_size, 0) << "Could not initialize shared memory.";
200204
t8_shmem_set_type (comm, shmem_type);
201205

202206
#if T8_ENABLE_MPI
@@ -246,7 +250,8 @@ TEST_P (shmem, test_shmem_array_prefix)
246250
const sc_shmem_type_t shmem_type = (sc_shmem_type_t) shmem_type_int;
247251

248252
/* setup shared memory usage */
249-
t8_shmem_init (comm);
253+
const int intranode_size = t8_shmem_init (comm);
254+
ASSERT_GT (intranode_size, 0) << "Could not initialize shared memory.";
250255
t8_shmem_set_type (comm, shmem_type);
251256

252257
#if T8_ENABLE_MPI
@@ -291,7 +296,8 @@ TEST_P (shmem, test_shmem_array)
291296
const sc_shmem_type_t shmem_type = (sc_shmem_type_t) shmem_type_int;
292297

293298
/* setup shared memory usage */
294-
t8_shmem_init (comm);
299+
const int intranode_size = t8_shmem_init (comm);
300+
ASSERT_GT (intranode_size, 0) << "Could not initialize shared memory.";
295301
t8_shmem_set_type (comm, shmem_type);
296302

297303
#if T8_ENABLE_MPI

0 commit comments

Comments
 (0)