next up previous contents
Next: The configuration file config.hh Up: The LogicalProcess class Previous: Telling the LP to

Other kernel defined data in an LP

Like the TimeWarp class, the LogicalProcess class has an integer id. Assuming the simulation is running in parallel and MPI is being used, the id should be the same as the rank assigned by MPI. If MPI is being used, the LogicalProcess will actually get the rank from MPI itself and initialize the id. However, there are times when the MPI_RANK needs to be known before the construction of the LogicalProcess. For instance, if there are two LPs in a simulation which we want to run on two networked workstations, we might want to use the same executable for both machines. We can use C++'s scoping mechanism to instantiate exactly what we need if we get our MPI_RANK before instantiating any simulation objects or LPs.

See the following example:

main(int argc, char *argv[]) {
  
  int id;

  MPI_Init( &argc, &argv );
  MPI_Comm_rank( MPI_COMM_WORLD, &id);

  if(id == 0) {
    LogicalProcess lp(2,1,2);  // total, local, LPs

    PingObject player0;
    player0.id = 0;
    player0.name = "player0";
    lp.registerObject(&player0);
  }
  else if (id == 1) {
    LogicalProcess lp(2,1,2);  // total, local, LPs

    PingObject player1;
    player1.id = 1;
    player1.name = "player1";
    lp.registerObject(&player1);
  }
}

Since the LPs are defined within the scope of the if tests, only those objects that need to will construct on each machine (or under each process.)



Philip A. Wilsey
1/26/1998