Skip to content

Commit 7e91f24

Browse files
committed
Fix threaded ring test: Use master's communicator for all threads.
1 parent d578cad commit 7e91f24

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

threaded/tst_threaded_ring.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,29 @@
1010
*
1111
* Date: Oct 26th 2006
1212
*/
13+
1314
#include <mpi.h>
1415
#include "mpi_test_suite.h"
1516
#include "tst_threads.h"
1617
#include "tst_output.h"
17-
18-
#ifdef HAVE_PTHREAD_H
19-
# include <pthread.h>
20-
#endif
18+
#include "tst_comm.h"
2119

2220

2321
int debug_wait = 1;
2422

2523
int tst_threaded_ring_init (struct tst_env * env)
2624
{
2725
// while (DebugWait) ;
28-
int comm_rank;
29-
MPI_Comm comm;
26+
int comm_rank = -1;
27+
MPI_Comm comm = MPI_COMM_NULL;
3028

3129
tst_output_printf (DEBUG_LOG, TST_REPORT_MAX, "(Rank:%d) env->comm:%d env->type:%d env->values_num:%d\n",
3230
tst_global_rank, env->comm, env->type, env->values_num);
3331

3432
env->send_buffer = tst_type_allocvalues (env->type, env->values_num);
3533
env->recv_buffer = tst_type_allocvalues (env->type, env->values_num);
3634

37-
comm = tst_comm_getcomm (env->comm);
35+
comm = tst_comm_getmastercomm (env->comm);
3836
MPI_CHECK (MPI_Comm_rank (comm, &comm_rank));
3937

4038
/* initialize the send_buffer */
@@ -53,21 +51,18 @@ int tst_threaded_ring_run (struct tst_env * env)
5351
MPI_Comm comm;
5452
MPI_Datatype type;
5553
MPI_Status status;
56-
int thread_num;
57-
int num_threads = tst_thread_num_threads();
58-
int thread_tag_to;
59-
int thread_tag_from;
54+
int num_threads = 1 + tst_thread_num_threads(); /* we have to add 1 for the master thread */
55+
int thread_num = (tst_thread_get_num() + num_threads) % num_threads;
6056

61-
thread_num = tst_thread_get_num();
62-
comm = tst_comm_getcomm (env->comm);
57+
comm = tst_comm_getmastercomm (env->comm);
6358
type = tst_type_getdatatype (env->type);
6459
/*
6560
* Calculate the tags to specify the number of the thread to send to and the thread
6661
* number to recieve from.
6762
* The tags are the sum of the constant env->tag and a threadspecific number.
6863
*/
69-
thread_tag_to = env->tag + (thread_num + 1) % num_threads; /* number of next thread */
70-
thread_tag_from = env->tag + (thread_num); /* already knows it's number */
64+
int thread_tag_to = env->tag + (thread_num + 1) % num_threads; /* number of next thread */
65+
int thread_tag_from = env->tag + thread_num; /* already knows it's number */
7166

7267
if (tst_comm_getcommclass (env->comm) & TST_MPI_COMM_SELF)
7368
{

tst_comm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,12 @@ MPI_Comm tst_comm_getcomm (int i) {
656656
}
657657
}
658658

659+
660+
MPI_Comm tst_comm_getmastercomm (int i) {
661+
CHECK_ARG (i, MPI_COMM_NULL);
662+
return comms[i].mpi_comm;
663+
}
664+
659665
int tst_comm_getcommsize (int i)
660666
{
661667
int size;

tst_comm.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef TST_COMM_H_
22
#define TST_COMM_H_
33

4+
#include <mpi.h>
5+
6+
47
/** \brief register communicators
58
*
69
* \return number of registered communicators
@@ -13,4 +16,19 @@ int tst_comms_register() ;
1316
*/
1417
int tst_comms_init();
1518

19+
/** \brief return thread private MPI communicator for given communicator
20+
*
21+
* \param[in] comm id of the communicator
22+
* \return a thread private MPI communicator
23+
*/
24+
MPI_Comm tst_comm_getcomm (int commId);
25+
26+
/** \brief Get master thread's MPI communicator for given communicator
27+
*
28+
* \param[in] comm id of the communicator
29+
* \return master thread's MPI communicator
30+
*/
31+
MPI_Comm tst_comm_getmastercomm(int commId);
32+
33+
1634
#endif /* TST_COMM_H_ */

0 commit comments

Comments
 (0)