Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Introduce smpi::Process
[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 <simgrid/s4u/host.hpp>
19
20 #include "src/kernel/activity/SynchroComm.hpp"
21
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)");
23
24 static simgrid::config::Flag<double> smpi_wtime_sleep(
25   "smpi/wtime", "Minimum time to inject inside a call to MPI_Wtime", 0.0);
26 static simgrid::config::Flag<double> smpi_init_sleep(
27   "smpi/init", "Time to inject inside a call to MPI_Init", 0.0);
28
29 void smpi_mpi_init() {
30   if(smpi_init_sleep > 0) 
31     simcall_process_sleep(smpi_init_sleep);
32 }
33
34 double smpi_mpi_wtime(){
35   double time;
36   if (smpi_process()->initialized() != 0 && smpi_process()->finalized() == 0 && smpi_process()->sampling() == 0) {
37     smpi_bench_end();
38     time = SIMIX_get_clock();
39     // to avoid deadlocks if used as a break condition, such as
40     //     while (MPI_Wtime(...) < time_limit) {
41     //       ....
42     //     }
43     // because the time will not normally advance when only calls to MPI_Wtime
44     // are made -> deadlock (MPI_Wtime never reaches the time limit)
45     if(smpi_wtime_sleep > 0) 
46       simcall_process_sleep(smpi_wtime_sleep);
47     smpi_bench_begin();
48   } else {
49     time = SIMIX_get_clock();
50   }
51   return time;
52 }
53
54 void smpi_empty_status(MPI_Status * status)
55 {
56   if(status != MPI_STATUS_IGNORE) {
57     status->MPI_SOURCE = MPI_ANY_SOURCE;
58     status->MPI_TAG = MPI_ANY_TAG;
59     status->MPI_ERROR = MPI_SUCCESS;
60     status->count=0;
61   }
62 }
63
64 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype)
65 {
66   return status->count / datatype->size();
67 }