Skip to content

Commit c4a4dab

Browse files
committed
Allocate mpi buffer only by one thread and test parameters of detached buffer
1 parent 977f78d commit c4a4dab

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

p2p/tst_p2p_simple_ring_ibsend.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*
1111
* Date: Aug 8th 2003
1212
*/
13+
#include <assert.h>
1314
#include <mpi.h>
1415
#include "mpi_test_suite.h"
1516
#include "tst_output.h"
@@ -41,28 +42,24 @@ int tst_p2p_simple_ring_ibsend_init (struct tst_env * env)
4142
env->send_buffer = tst_type_allocvalues (env->type, env->values_num);
4243
env->recv_buffer = tst_type_allocvalues (env->type, env->values_num);
4344

44-
#ifdef HAVE_MPI2_THREADS
45-
num_threads = tst_thread_num_threads ();
46-
#endif
4745
/*
4846
* Now, initialize the send_buffer
4947
*/
5048
comm = tst_comm_getcomm (env->comm);
5149
MPI_CHECK (MPI_Comm_rank (comm, &comm_rank));
52-
5350
tst_type_setstandardarray (env->type, env->values_num, env->send_buffer, comm_rank);
5451

55-
env->mpi_buffer_size = num_threads * (tst_type_gettypesize (env->type) * env->values_num + MPI_BSEND_OVERHEAD);
56-
if ((env->mpi_buffer = malloc (env->mpi_buffer_size)) == NULL)
57-
ERROR (errno, "malloc");
58-
5952
/*
6053
* The buffer may be attached by one thread of the processes, only
6154
* Actually, the standard doesn't even say so.
6255
*/
6356
#ifdef HAVE_MPI2_THREADS
6457
if ( tst_thread_get_num() == 0 ) {
6558
#endif
59+
num_threads = tst_thread_num_threads ();
60+
env->mpi_buffer_size = num_threads * (tst_type_gettypesize (env->type) * env->values_num + MPI_BSEND_OVERHEAD);
61+
if ((env->mpi_buffer = malloc (env->mpi_buffer_size)) == NULL)
62+
ERROR (errno, "malloc");
6663
MPI_CHECK (MPI_Buffer_attach (env->mpi_buffer, env->mpi_buffer_size));
6764
#ifdef HAVE_MPI2_THREADS
6865
}
@@ -141,7 +138,11 @@ int tst_p2p_simple_ring_ibsend_cleanup (struct tst_env * env)
141138
#ifdef HAVE_MPI2_THREADS
142139
if ( tst_thread_get_num () == 0 ) {
143140
#endif
144-
MPI_CHECK (MPI_Buffer_detach (&env->mpi_buffer, &env->mpi_buffer_size));
141+
void *buf;
142+
int size = -1;
143+
MPI_CHECK (MPI_Buffer_detach (&buf, &size));
144+
assert(env->mpi_buffer == buf);
145+
assert(env->mpi_buffer_size == size);
145146
#ifdef HAVE_MPI2_THREADS
146147
}
147148
#endif

0 commit comments

Comments
 (0)