10
10
*
11
11
* Date: Oct 26th 2006
12
12
*/
13
+
13
14
#include <mpi.h>
14
15
#include "mpi_test_suite.h"
15
16
#include "tst_threads.h"
16
17
#include "tst_output.h"
17
-
18
- #ifdef HAVE_PTHREAD_H
19
- # include <pthread.h>
20
- #endif
18
+ #include "tst_comm.h"
21
19
22
20
23
21
int debug_wait = 1 ;
24
22
25
23
int tst_threaded_ring_init (struct tst_env * env )
26
24
{
27
25
// while (DebugWait) ;
28
- int comm_rank ;
29
- MPI_Comm comm ;
26
+ int comm_rank = -1 ;
27
+ MPI_Comm comm = MPI_COMM_NULL ;
30
28
31
29
tst_output_printf (DEBUG_LOG , TST_REPORT_MAX , "(Rank:%d) env->comm:%d env->type:%d env->values_num:%d\n" ,
32
30
tst_global_rank , env -> comm , env -> type , env -> values_num );
33
31
34
32
env -> send_buffer = tst_type_allocvalues (env -> type , env -> values_num );
35
33
env -> recv_buffer = tst_type_allocvalues (env -> type , env -> values_num );
36
34
37
- comm = tst_comm_getcomm (env -> comm );
35
+ comm = tst_comm_getmastercomm (env -> comm );
38
36
MPI_CHECK (MPI_Comm_rank (comm , & comm_rank ));
39
37
40
38
/* initialize the send_buffer */
@@ -53,21 +51,18 @@ int tst_threaded_ring_run (struct tst_env * env)
53
51
MPI_Comm comm ;
54
52
MPI_Datatype type ;
55
53
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 ;
60
56
61
- thread_num = tst_thread_get_num ();
62
- comm = tst_comm_getcomm (env -> comm );
57
+ comm = tst_comm_getmastercomm (env -> comm );
63
58
type = tst_type_getdatatype (env -> type );
64
59
/*
65
60
* Calculate the tags to specify the number of the thread to send to and the thread
66
61
* number to recieve from.
67
62
* The tags are the sum of the constant env->tag and a threadspecific number.
68
63
*/
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 */
71
66
72
67
if (tst_comm_getcommclass (env -> comm ) & TST_MPI_COMM_SELF )
73
68
{
0 commit comments