Skip to content

Commit 5e64e4d

Browse files
committed
Seperate comm registration from comm initialisation
1 parent 9f30d49 commit 5e64e4d

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

mpi_test_suite.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <mpi.h>
1111

1212
#include "mpi_test_suite.h"
13+
#include "tst_comm.h"
1314
#include "tst_threads.h"
1415
#include "tst_output.h"
1516
#include "compile_info.h"
@@ -258,7 +259,7 @@ int main (int argc, char * argv[])
258259
tst_global_rank, tst_tag_ub);
259260

260261
/* XXX CN Maybe rename these functions to tst_get_num_comms/types/tests ? */
261-
tst_comms_init(&num_comms);
262+
num_comms = tst_comms_register();
262263
tst_type_init(&num_types);
263264
tst_test_init(&num_tests);
264265

@@ -567,6 +568,7 @@ int main (int argc, char * argv[])
567568
tst_thread_init (num_threads, &tst_thread_env);
568569
#endif
569570

571+
num_comms = tst_comms_init();
570572
/*
571573
* For every test included in the tst_*_array, check if runnable and run!
572574
*/

mpi_test_suite.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ struct tst_thread_env_t; /* Just a forward declaration */
393393
/** EXPORTED FUNCTIONS **/
394394
/** **/
395395
/****************************************************************************/
396-
extern int tst_comms_init (int * num_comms);
397396
extern int tst_comm_cleanup (void);
398397
extern MPI_Comm tst_comm_getcomm (int comm);
399398
extern int tst_comm_getcommclass (int comm);

tst_comm.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "config.h"
44

5+
#include "tst_comm.h"
6+
57
#include <assert.h>
68
#include <stdio.h>
79
#include <stdlib.h>
@@ -55,21 +57,25 @@ static int num_registered_comms = 0;
5557
static struct comm comms[COMM_NUM];
5658

5759

58-
int tst_comm_register(char *description, MPI_Comm mpi_comm, int class, int size, int *mapping, int other_size, int *other_mapping) {
59-
assert(num_registered_comms < COMM_NUM);
60+
int tst_comm_init(struct comm *comm) {
6061
int i;
6162
int num_threads = tst_thread_num_threads();
62-
comms[num_registered_comms].mpi_comm = mpi_comm;
63-
comms[num_registered_comms].mpi_thread_comms = (MPI_Comm *) malloc(num_threads * sizeof(MPI_Comm));
63+
comm->mpi_thread_comms = (MPI_Comm *) malloc(num_threads * sizeof(MPI_Comm));
6464
for (i = 0; i < num_threads; i++) {
65-
if(mpi_comm != MPI_COMM_NULL) {
66-
MPI_CHECK (MPI_Comm_dup(mpi_comm, &comms[num_registered_comms].mpi_thread_comms[i]));
65+
if(comm->mpi_comm != MPI_COMM_NULL) {
66+
MPI_CHECK (MPI_Comm_dup(comm->mpi_comm, &comm->mpi_thread_comms[i]));
6767
}
6868
else {
69-
comms[num_registered_comms].mpi_thread_comms[i] = MPI_COMM_NULL;
69+
comm->mpi_thread_comms[i] = MPI_COMM_NULL;
7070
}
7171
}
72+
return 0;
73+
}
74+
75+
int tst_comm_register(char *description, MPI_Comm mpi_comm, int class, int size, int *mapping, int other_size, int *other_mapping) {
76+
assert(num_registered_comms < COMM_NUM);
7277
strncpy(comms[num_registered_comms].description, description, TST_DESCRIPTION_LEN);
78+
comms[num_registered_comms].mpi_comm = mpi_comm;
7379
comms[num_registered_comms].class = class;
7480
comms[num_registered_comms].size = size;
7581
comms[num_registered_comms].mapping = mapping;
@@ -425,7 +431,15 @@ int tst_comm_register_split_type_shared() {
425431
}
426432

427433

428-
int tst_comms_init(int * num_comms) {
434+
int tst_comms_init() {
435+
int i;
436+
for (i = 0; i < num_registered_comms; i++) {
437+
tst_comm_init(&comms[i]);
438+
}
439+
return num_registered_comms;
440+
}
441+
442+
int tst_comms_register() {
429443

430444
tst_comm_register_comm_world();
431445
tst_comm_register_comm_null();
@@ -441,14 +455,14 @@ int tst_comms_init(int * num_comms) {
441455
tst_comm_register_merged_inter_comm();
442456
tst_comm_register_split_type_shared();
443457

444-
*num_comms = num_registered_comms;
445-
return 0;
458+
return num_registered_comms;
446459

447460
int count_comms = num_registered_comms;
448461
int comm_size;
449462
int comm_rank;
450463
MPI_Comm tmp_comm = MPI_COMM_NULL;
451464
int i;
465+
int * num_comms;
452466

453467
MPI_Comm_size (MPI_COMM_WORLD, &comm_size);
454468
MPI_Comm_rank (MPI_COMM_WORLD, &comm_rank);

tst_comm.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TST_COMM_H_
2+
#define TST_COMM_H_
3+
4+
/** \brief register communicators
5+
*
6+
* \return number of registered communicators
7+
*/
8+
int tst_comms_register() ;
9+
10+
/** \brief initialize communicators
11+
*
12+
* \return number of initialized communicators
13+
*/
14+
int tst_comms_init();
15+
16+
#endif /* TST_COMM_H_ */

0 commit comments

Comments
 (0)