Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
86f22315cce1737bfacab26b7a5561ae8a2e419e
[simgrid.git] / src / smpi / smpi_base.cpp
1 /* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <xbt/config.hpp>
7 #include <algorithm>
8
9 #include "private.h"
10 #include "xbt/virtu.h"
11 #include "mc/mc.h"
12 #include "src/mc/mc_replay.h"
13 #include <errno.h>
14 #include "src/simix/smx_private.h"
15 #include "surf/surf.h"
16 #include "simgrid/sg_config.h"
17 #include "smpi/smpi_utils.hpp"
18 #include "colls/colls.h"
19 #include <simgrid/s4u/host.hpp>
20
21 #include "src/kernel/activity/SynchroComm.hpp"
22
23 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)");
24
25 static simgrid::config::Flag<double> smpi_wtime_sleep(
26   "smpi/wtime", "Minimum time to inject inside a call to MPI_Wtime", 0.0);
27 static simgrid::config::Flag<double> smpi_init_sleep(
28   "smpi/init", "Time to inject inside a call to MPI_Init", 0.0);
29
30 void smpi_mpi_init() {
31   if(smpi_init_sleep > 0) 
32     simcall_process_sleep(smpi_init_sleep);
33 }
34
35 double smpi_mpi_wtime(){
36   double time;
37   if (smpi_process_initialized() != 0 && smpi_process_finalized() == 0 && smpi_process_get_sampling() == 0) {
38     smpi_bench_end();
39     time = SIMIX_get_clock();
40     // to avoid deadlocks if used as a break condition, such as
41     //     while (MPI_Wtime(...) < time_limit) {
42     //       ....
43     //     }
44     // because the time will not normally advance when only calls to MPI_Wtime
45     // are made -> deadlock (MPI_Wtime never reaches the time limit)
46     if(smpi_wtime_sleep > 0) 
47       simcall_process_sleep(smpi_wtime_sleep);
48     smpi_bench_begin();
49   } else {
50     time = SIMIX_get_clock();
51   }
52   return time;
53 }
54
55 void smpi_empty_status(MPI_Status * status)
56 {
57   if(status != MPI_STATUS_IGNORE) {
58     status->MPI_SOURCE = MPI_ANY_SOURCE;
59     status->MPI_TAG = MPI_ANY_TAG;
60     status->MPI_ERROR = MPI_SUCCESS;
61     status->count=0;
62   }
63 }
64
65 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype)
66 {
67   return status->count / datatype->size();
68 }