From e9ad85cc4964fb312806817ba27c917c9d797207 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Fri, 14 Feb 2014 15:52:22 +0100 Subject: [PATCH] protect smpi against problems with replay+collectives. Previous protection was ignoring NULL as a buffer. But some collective algorithms use chunks of data from the buffer, instead, trying to use NULL+offset as an address. --- include/xbt/replay.h | 2 ++ src/smpi/smpi_base.c | 2 +- src/smpi/smpi_global.c | 2 ++ src/smpi/smpi_mpi_dt.c | 4 +++- src/xbt/xbt_replay.c | 6 ++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/xbt/replay.h b/include/xbt/replay.h index 196ce79219..675a5ad6a9 100644 --- a/include/xbt/replay.h +++ b/include/xbt/replay.h @@ -28,6 +28,8 @@ XBT_PUBLIC(const char *) xbt_replay_reader_position(xbt_replay_reader_t reader); XBT_PUBLIC(int) xbt_replay_action_runner(int argc, char *argv[]); +XBT_PUBLIC(int) _xbt_replay_is_active(void); + XBT_PUBLIC(void) _xbt_replay_action_init(void); XBT_PUBLIC(void) _xbt_replay_action_exit(void); diff --git a/src/smpi/smpi_base.c b/src/smpi/smpi_base.c index 1887ec0067..b72d6ce9b0 100644 --- a/src/smpi/smpi_base.c +++ b/src/smpi/smpi_base.c @@ -370,7 +370,7 @@ void smpi_mpi_start(MPI_Request request) request->refcount++; if(request->old_type->has_subtype == 0){ oldbuf = request->buf; - if (oldbuf && request->size!=0){ + if (!_xbt_replay_is_active() && oldbuf && request->size!=0){ request->buf = xbt_malloc(request->size); memcpy(request->buf,oldbuf,request->size); } diff --git a/src/smpi/smpi_global.c b/src/smpi/smpi_global.c index 876889f687..89f5cb507a 100644 --- a/src/smpi/smpi_global.c +++ b/src/smpi/smpi_global.c @@ -7,6 +7,7 @@ #include "private.h" #include "smpi_mpi_dt_private.h" #include "mc/mc.h" +#include "xbt/replay.h" #include "surf/surf.h" #include "simix/smx_private.h" #include "simgrid/sg_config.h" @@ -318,6 +319,7 @@ static void smpi_comm_copy_buffer_callback(smx_action_t comm, void *buff, size_t buff_size) { XBT_DEBUG("Copy the data over"); + if(_xbt_replay_is_active()) return; memcpy(comm->comm.dst_buff, buff, buff_size); if (comm->comm.detached) { // if this is a detached send, the source buffer was duplicated by SMPI diff --git a/src/smpi/smpi_mpi_dt.c b/src/smpi/smpi_mpi_dt.c index eb1d71cd1e..8be8134291 100644 --- a/src/smpi/smpi_mpi_dt.c +++ b/src/smpi/smpi_mpi_dt.c @@ -14,6 +14,7 @@ #include "private.h" #include "smpi_mpi_dt_private.h" #include "mc/mc.h" +#include "xbt/replay.h" #include "simgrid/modelchecker.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi_dt, smpi, @@ -165,7 +166,7 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, count = sendcount < recvcount ? sendcount : recvcount; if(sendtype->has_subtype == 0 && recvtype->has_subtype == 0) { - memcpy(recvbuf, sendbuf, count); + if(!_xbt_replay_is_active()) memcpy(recvbuf, sendbuf, count); } else if (sendtype->has_subtype == 0) { @@ -1488,5 +1489,6 @@ void smpi_op_destroy(MPI_Op op) void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, MPI_Datatype * datatype) { + if(!_xbt_replay_is_active()) op->func(invec, inoutvec, len, datatype); } diff --git a/src/xbt/xbt_replay.c b/src/xbt/xbt_replay.c index 211940dcc6..ffd80026a3 100644 --- a/src/xbt/xbt_replay.c +++ b/src/xbt/xbt_replay.c @@ -31,6 +31,8 @@ xbt_dict_t action_queues; static char *action_line = NULL; static size_t action_len = 0; +int is_replay_active = 0 ; + static char **action_get_action(char *name); static char *str_tolower (const char *str) @@ -42,6 +44,9 @@ static char *str_tolower (const char *str) return ret; } +int _xbt_replay_is_active(void){ + return is_replay_active; +} xbt_replay_reader_t xbt_replay_reader_new(const char *filename) { @@ -127,6 +132,7 @@ void xbt_replay_action_unregister(const char *action_name) void _xbt_replay_action_init(void) { + is_replay_active = 1; action_funs = xbt_dict_new_homogeneous(NULL); action_queues = xbt_dict_new_homogeneous(NULL); } -- 2.20.1