Library Initialization

Library Initialization#

Initialization of the library is done using the mass::Mass::init() function, which will prepare all the components for running the simulation. No APIs should be invoked before this function is called.

At the end of simulation, the library should be shutdown gracefully using the mass::Mass::finish() function to release all the resources. No APIs should be invoked after this function is called.

To make sure the lifecycle of the library is handled correctly, it is recomended to use the MASS_SCOPE_DEFER macro to automatically handle the cleanup process, which guarantees that the library will be properly shutdown even when exceptions are thrown.

mass::Mass::init();
MASS_SCOPE_DEFER() { mass::Mass::finish(); }

// your simulation implementations with MASS CUDA APIs ...

Initialization Configuration#

The initialization of the library can be configured with CLI arguments. To do that, pass the argc and argv arguments received from the main function to the mass::Mass::init() function.

int main(int argc, char* argv[]) {
    mass::Mass::init(argc, argv);
    MASS_SCOPE_DEFER() { mass::Mass::finish(); }

    // your simulation implementations with MASS CUDA APIs ...

    return 0;
}

Currently, the only configuration option is the mass-nodes-config-file, which is path to the configuration file specifying information of all the participating nodes. If it is not provided, the library will assume that the current process is the only node for the simulation.

Nodes Configuration File#

An XML file containing information of all the nodes that should be included in the simulation, which should include the hostname, port, path to dir of the executable, username and path to the ssh key. The format of the file is as follows:

<nodes>
    <node>
        <hostname>host0</hostname>
        <port>12345</port>
        <username>user</username>
        <masshome>/home/serika/simulation/DSLab/</masshome>
        <privatekey>/home/serika/.ssh/id_ed25519</privatekey>
    </node>
    <node>
        <hostname>host1</hostname>
        <port>12345</port>
        <username>user</username>
        <masshome>/home/serika/simulation/DSLab/</masshome>
        <privatekey>/home/serika/.ssh/id_ed25519</privatekey>
    </node>
    <!-- more nodes here... -->
</nodes>

The index of each node in the file is used as the rank of that node in the simulation and the node with rank 0 is treated as the master node. As a result, the first node in the list is always the master node.