SimGrid simulator installation and application - high performance computing simulator


1. About simgrid

2.SimGrid installation

2.1 Binaries for Linux

2.2 Installing from the Source

3.SimGrid code running

3.1 code download

3.2 write C + + code and run it


1. About simgrid

SimGrid is a widely used simulator, whose homepage is [1] , its brief introduction is as follows:

In short, it can simulate some distributed applications on a single machine and support the development support of C + + / Python 3 / Java. The first step of the application is to install, but at present, there are few Chinese materials about the use and installation of SimGrid on the Internet, so I will make a record here for your reference. I choose the simplest Linux system to install.

2.SimGrid installation

2.1 Binaries for Linux

For this installation, you can follow the steps on the website to install directly:

apt install libsimgrid-dev  # if you want to develop in C or C++
apt install simgrid-java    # if you want to develop in Java
apt install python3-simgrid # if you want to develop in Python

However, this installation is version 3.18. At present, the demo on the official website is above 3.22, so this installation is not recommended.

2.2 Installing from the Source

Second, you can install the source code. First, you need to download the dependency (there are more detailed steps on the official website [2],

Getting the Dependencies
1. C++ compiler (either g++, clang, or icc).
   We use the C++11 standard, and older compilers tend to fail on us. It seems that g++  5.0 or higher is required nowadays (because of boost). SimGrid compiles well with clang or icc too.

2. Python 3.
   SimGrid should build without Python. That is only needed by our regression test suite.

3. cmake (v3.5).
   ccmake provides a nicer graphical interface compared to cmake. Press t in ccmake if you need to see absolutely all configuration options (e.g., if your Python installation is not standard).

4. boost (at least v1.48, v1.59 recommended)
   On Debian / Ubuntu: apt install libboost-dev libboost-context-dev
   On macOS with homebrew: brew install boost

5. Java (optional):
   Debian / Ubuntu: apt install default-jdk libgcj18-dev (or any version of libgcj)
   macOS or Windows: Grab a full JDK

6. Lua (optional – must be v5.3)
   SimGrid won't work with any other version of Lua.
   Debian / Ubuntu: apt install liblua5.3-dev lua5.3
   Windows: choco install lua53
   From the source
   You need to patch the sources to build dynamic libraries. First download lua 5.3 
   Open the archive: tar xvfz lua-5.3.*.tar.gz
   Enter the directory: cd lua-5.3*
   Patch the sources: patch -p1 < /path/to/simgrid/...../tools/lualib.patch
   Build and install lua: make linux && sudo make install

Secondly, from FramaGit Download source code [3]:

Then execute:

tar xf SimGrid-3-XX.tar.gz
cd SimGrid-*
cmake -DCMAKE_INSTALL_PREFIX=/opt/simgrid .
make install

Where make install means

Install the project (doc/ bin/ lib/ include/)

To check whether the installation is successful, you can execute it in the first directory after decompression:

make tests                # Build the tests
ctest                     # Launch all tests
ctest -R s4u              # Launch only the tests whose names match the string "s4u"
ctest -j4                 # Launch all tests in parallel, at most 4 concurrent jobs
ctest --verbose           # Display all details on what's going on
ctest --output-on-failure # Only get verbose for the tests that fail

ctest -R s4u -j4 --output-on-failure # You changed S4U and want to check that you didn't break anything, huh?
                                     # That's fine, I do so all the time myself.

If the installation is successful, it will be executed correctly, as shown below:


3.SimGrid code running

According to the above steps, SimGrid has been successfully installed, so you can write code to run,

3.1 code download

All files can be downloaded directly from the website [4]

3.2 write C + + code and run it

I have rewritten the C + + code according to the demo on the official website. The detailed text can be read from [1].

1. masteworkers.cpp

#include "simgrid/s4u.hpp"
#include <string>
using namespace std;
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");

static void master(std::vector<std::string> args)
  xbt_assert(args.size() > 4, "The master function expects at least 3 arguments");

  long tasks_count          = std::stol(args[1]);
  double compute_cost       = std::stod(args[2]);
  double communication_cost = std::stod(args[3]);
  std::vector<simgrid::s4u::Mailbox*> workers;
  for (unsigned int i = 4; i < args.size(); i++)

  XBT_INFO("Got %zu workers and %ld tasks to process", workers.size(), tasks_count);

  for (int i = 0; i < tasks_count; i++) { /* For each task to be executed: */
    /* - Select a worker in a round-robin way */
    simgrid::s4u::Mailbox* mailbox = workers[i % workers.size()];

    /* - Send the computation cost to that worker */
    XBT_INFO("Sending task %d of %ld to mailbox '%s'", i, tasks_count, mailbox->get_cname());
    mailbox->put(new double(compute_cost), communication_cost);

  XBT_INFO("All tasks have been dispatched. Request all workers to stop.");
  for (unsigned int i = 0; i < workers.size(); i++) {
    /* The workers stop when receiving a negative compute_cost */
    simgrid::s4u::Mailbox* mailbox = workers[i % workers.size()];

    mailbox->put(new double(-1.0), 0);

static void worker(std::vector<std::string> args)
  xbt_assert(args.size() == 1, "The worker expects no argument");

  const simgrid::s4u::Host* my_host = simgrid::s4u::this_actor::get_host();
  simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name(my_host->get_name());

  double compute_cost;
  do {
    const double* msg = static_cast<double*>(mailbox->get());
    compute_cost = *msg;
    delete msg;

    if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
  } while (compute_cost > 0); /* Stop when receiving an invalid compute_cost */

  XBT_INFO("Exiting now.");

int main(int argc, char* argv[])
  simgrid::s4u::Engine e(&argc, argv);
  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n", argv[0]);

  /* Register the functions representing the actors */
  e.register_function("master", &master);
  e.register_function("worker", &worker);

  /* Load the platform description and then deploy the application */

  /* Run the simulation */;

  XBT_INFO("Simulation is over");

  return 0;

2. Load the corresponding Platform.xml and deploy.xml

3. This is very critical. You can't directly use g + + to compile programs. You must use the corresponding CMakeList.txt. Because my SimGrid is 3.25, my content is modified according to the demo file:

cmake_minimum_required(VERSION 2.8.8)

project(SimGridLinweieran) # TODO: give a real name to your project here

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(SimGrid 3.25 REQUIRED) # This template requires SimGrid v3.25


add_executable(masterworkers masterworkers.cpp)
target_link_libraries(masterworkers ${SimGrid_LIBRARY})

4. Replace foundSIMGrid file. Although you download your own file, you will not find the error of SimGrid. Choose to replace the same file in the root directory of the downloaded file Tree.

All the documents are:

5. Then execute: cmake. Generate the following file.

6. Execute make

7. Execute. / masterworkers small [platform.xml deploy.xml

The execution result is:

After that, you can write your own program to simulate the operation.


[1] Homepage of simgrid-3.25 user manual:

[2] SimGrid-3.25 installation steps:

[3] SimGrid source code download address:

[4] SimGrid C++ demo download address:

63 original articles published, 61 praised, 110000 visitors+
Private letter follow

Tags: Python cmake Linux Java

Posted on Tue, 11 Feb 2020 12:52:53 -0500 by dhillarun