Learn » Tutorial

Tutorial of how to use vt

Initializing/Finalizing

To initialize vt all you must do is invoke the vt::initialize call with the program arguments, which creates and initializes a new vt runtime. The initialize call reads the vt arguments and removes them, leaving the remaining for the program.

int main(int argc, char** argv) {
  vt::initialize(argc, argv);
   // program here
  vt::finalize();
}

If you are already using MPI in your program already, you don't want to call initialize like this because vt will initialize MPI itself. Instead, you should pass a pointer to the live MPI communicator to vt for it to clone, as so:

int main(int argc, char** argv) {
  MPI_Init(&argc, &argv);
  vt::initialize(argc, argv, &MPI_COMM_WORLD);
   // program here
  vt::finalize();
  MPI_Finalize();
}

If, for any reason, you want to predefine configuration, you can do it by creating AppConfig object, setting its members as you wish, and passing it to vt::initialize:

int main(int argc, char** argv) {
  arguments::AppConfig appConfig{};
  appConfig.vt_lb_name = "RotateLB";
  appConfig.vt_lb_data = true;

  vt::initialize(argc, argv, &appConfig);
   // program here
  vt::finalize();
}

You can do also do it if you initialized MPI on your own:

int main(int argc, char** argv) {
  MPI_Init(&argc, &argv);

  arguments::AppConfig appConfig{};
  appConfig.vt_lb_name = "RotateLB";
  appConfig.vt_lb_data = true;

  vt::initialize(argc, argv, &MPI_COMM_WORLD, &appConfig);
   // program here
  vt::finalize();
  MPI_Finalize();
}

It is worth noting that if you run your application with any of vt's command-line arguments and at the same time you define and pass AppConfig to vt::initialize, CLI arguments have a higher priority. In other words, if you predefine in source code and give from the command line the same vt's argument, but with a different value, the program will use the CLI one.

There is also an option to use configuration file. Refer to CLI11 documentation for details https://cliutils.github.io/CLI11/book/chapters/config.html. Important thing to remember - CLI11 processes configuration file before command line arguments, so in the end command line arguments might overwrite values defined in configuration file.

Tutorial Code Snippets

This page walks through the tutorial that exists in the source code. See vt/tutorial/*.h for the tutorial pieces in the repository. The main tutorial example code that stitches the pieces together is located in example: vt/tutorial/tutorial_main.h. The actual code that compiles into an example is in vt/examples/tutorial.cc.