Skip to content

Instantly share code, notes, and snippets.

@JRodez
Created December 19, 2023 19:03
Show Gist options
  • Save JRodez/e5f3b22fdecaa9285c1fb905e479b330 to your computer and use it in GitHub Desktop.
Save JRodez/e5f3b22fdecaa9285c1fb905e479b330 to your computer and use it in GitHub Desktop.
SimGrid cpp platform to expanded xml
#include <simgrid/instr.h>
#include <simgrid/s4u.hpp>
#include <simgrid/s4u/Host.hpp>
// #include "simgrid/s4u.hpp"
#include <xbt/log.h>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
#include <string>
#include <sstream>
int main(int argc, char **argv)
{
simgrid::s4u::Engine e(&argc, argv);
xbt_assert(argc == 3, "Usage: %s <platform_file> <flatify.xml>", argv[0]);
e.load_platform(argv[1]);
e.seal_platform();
const std::string outputfile(argv[2]);
const std::string extension = outputfile.substr(outputfile.find_last_of(".") + 1);
if (extension == "xml")
{
printf("Dumping to %s\n", outputfile.c_str());
std::string xmls = e.flatify_platform();
FILE *file = fopen(outputfile.c_str(), "w");
if (file == nullptr)
{
xbt_die("Cannot open file %s", outputfile.c_str());
}
fprintf(file, "%s", xmls.c_str());
fclose(file);
}
else
xbt_die("Unknown output file format, please use '.csv' or .json' extension");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment