Skip to content
Raul edited this page Dec 17, 2020 · 5 revisions

System is the base UAMMD module, any other module or submodule needs a reference to a System instance.
System contains information about the machine UAMMD is running on and offers a series of utilities like a CPU random number generator and a logging infrastructure. Furthermore, System handles initializing and deleting the CUDA environment (i.e selecting a GPU to run on).

System should be the first thing to create in a UAMMD simulation file[1], see any of the examples in examples folder.

USAGE

You should create a System first thing before any UAMMD call and call sys->finish last thing.

...
int main(int argc, char *argv[]){
  auto sys = std::make_shared<System>(argc, argv);
  //You may seed the rng algorithm here. The default seed is obtained from time(NULL).
  sys->rng().setSeed(time(NULL));
...
  //This will ensure the termination of any UAMMD related operation.
  sys->finish();
  return 0;
}

Random numbers

You can access a Xorshift128plus random generator from System. This generator should be used for things like seeding other generators, maybe creating initial configurations.

...
//Set the seed of the rng
sys->rng().setSeed(123124);
//Get a random integer between 0 and 2^64-1
uint64_t Z64 = sys->rng().next();
//Get a random integer between 0 and 2^32-1
uint32_t Z32 = sys->rng().next32();
//Get a uniform number between a and b
double a=0, b=1;
double Zf = sys->rng().uniform(a,b);
//Get a gaussian number with mean a and std b
double Zg = sys->rng().gaussian(a,b);
...

Logging

System provides a logging engine with several levels of relevance for the message. The available levels are in the System::level enum in System.h. You can see the following in this example:

  sys->log<System::CRITICAL>("The program will be terminated after printing this message!");
  sys->log<System::ERROR>("There was an error, but I might be able to circumvent it!");
  sys->log<System::WARNING>("Something happen that might be problematic, watch out! (I will keep running OK though)");
  sys->log<System::MESSAGE>("Here you have some useful information I want you to know!");
  sys->log<System::STDERR>("This goes straight to stderr");
  sys->log<System::STDOUT>("This goes straight to stdout");
  sys->log<System::DEBUG>("A debug message!");
  sys->log<System::DEBUG1>("A more internal debug message!");
  ...
  sys->log<System::DEBUG7>("There are 7 levels of debug!");

The maximum level of logging that will be processed will be the compile constant maxLogLevel in Log.h. Anything below this level will not even be compiled, so do not be worried about performance when writing debug logs. The highest level of logging that will print DEBUG messages is maxLogLevel = 6. maxLoglevel=13 will print up to DEBUG7, while maxLogLevel=0 will only print CRITICAL errors.

Other methods

int getargc(), char** getargv() -> returns the argc and argv provided at System creation.

References

[1] https://github.com/RaulPPelaez/UAMMD/wiki/Simulation-File









Clone this wiki locally