/* gras/emul.h - public interface to emulation support */ /* (specific parts for SG or RL) */ /* Copyright (c) 2005, 2006, 2007, 2009, 2010. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #ifndef GRAS_COND_H #define GRAS_COND_H #include "xbt/misc.h" /* SG_BEGIN_DECL */ SG_BEGIN_DECL() /** @addtogroup GRAS_emul * @brief Code execution "emulation" and "virtualization". * * Emulation and virtualization words have a lot of different meanings in * computer science. Here is what we mean, and what this module allows you * to do (if it does not match your personal belives, I'm sorry): * * - Virtualization: Having some specific code for the simulation or for the reality * - Emulation: Report within the simulator the execution time of your code * * \section GRAS_emul_virtualization Virtualization * * The whole idea of GRAS is to share the same code between the simulator * and the real implementation. But it is sometimes impossible, such as * when you want to deal with the OS. As an example, you may want to add * some extra delay before initiating a communication in RL to ensure that * the receiver is listening. This is usually useless in SG since you have * a much better control on process launch time. * * This would be done with the following snipet: * \verbatim if (gras_if_RL()) gras_os_sleep(1);\endverbatim * * Please note that those are real functions and not pre-processor * defines. This is to ensure that the same object code can be linked * against the SG library or the RL one without recompilation. * * @{ */ /** \brief Returns true only if the program runs on real life */ XBT_PUBLIC(int) gras_if_RL(void); /** \brief Returns true only if the program runs within the simulator */ XBT_PUBLIC(int) gras_if_SG(void); /** @} */ XBT_PUBLIC(int) gras_bench_always_begin(const char *location, int line); XBT_PUBLIC(int) gras_bench_always_end(void); XBT_PUBLIC(int) gras_bench_once_begin(const char *location, int line); XBT_PUBLIC(int) gras_bench_once_end(void); /** @addtogroup GRAS_emul * \section GRAS_emul_timing Emulation * * For simulation accuracy, it is mandatory to report the execution time * of your code into the simulator. For example, if your application is a * parallel matrix multiplication, you naturally have to slow down the * simulated hosts actually doing the computation. * * If you know beforehands how long each task will last, simply add a call * to the gras_bench_fixed function described below. If not, you can have * GRAS benchmarking your code automatically. Simply enclose the code to * time between a macro GRAS_BENCH_*_BEGIN and GRAS_BENCH_*_END, and * you're done. There is three pair of such macros, whose characteristics * are summarized in the following table. * *
Name | *Run on host machine? | *Benchmarked? | *Corresponding time reported to simulation? | *
GRAS_BENCH_ALWAYS_BEGIN() * GRAS_BENCH_ALWAYS_END() |
* Each time | *Each time | *Each time | *
GRAS_BENCH_ONCE_RUN_ONCE_BEGIN() * GRAS_BENCH_ONCE_RUN_ONCE_END() |
* Only first time | *Only first time | *Each time (with stored value) | *
GRAS_BENCH_ONCE_RUN_ALWAYS_BEGIN() * GRAS_BENCH_ONCE_RUN_ALWAYS_END() |
* Each time | *Only first time | *Each time (with stored value) | *