GooFit  v2.1.3
Public Member Functions | Protected Attributes | List of all members
GooFit::Application Class Reference

#include <Application.h>

Inheritance diagram for GooFit::Application:

Public Member Functions

 Application (std::string discription, int argc, char **argv)
 Make a new Application. More...
 
 Application (int argc, char **argv)
 Shortcut for the lazy. More...
 
int get_device () const
 Get the set GPU device. More...
 
void run ()
 simple run since argc and argv are stored More...
 
void pre_callback () override
 Gets called in parse. More...
 
int exit (const CLI::Error &e)
 Exit. More...
 
void set_device () const
 
 ~Application () override
 Cleanup MPI if needed. More...
 
std::string get_filename (const std::string &input_str, std::string base="") const
 

Protected Attributes

int gpuDev_ = 0
 
bool show_gpus_
 
bool quiet_
 
bool splash_
 
int argc_
 
char ** argv_
 
struct sigaction sigIntHandler
 Handle control-c codes. More...
 

Detailed Description

Definition at line 42 of file Application.h.

Constructor & Destructor Documentation

◆ Application() [1/2]

GooFit::Application::Application ( std::string  discription,
int  argc,
char **  argv 
)

Make a new Application.

Definition at line 124 of file Application.cpp.

References argc_, argv_, gpuDev_, quiet_, GooFit::reset, show_gpus_, sigIntHandler, GooFit::signal_handler(), and splash_.

125  : App(discription)
126  , argc_(argc)
127  , argv_(argv) {
128 #ifdef GOOFIT_MPI
129  MPI_Init(&argc_, &argv_);
130 
131  int myId, numProcs;
132  MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
133  MPI_Comm_rank(MPI_COMM_WORLD, &myId);
134 
135 #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
136  int deviceCount;
137  cudaGetDeviceCount(&deviceCount);
138 
139  // Get Batch system number of nodes if possible
140  auto PBS_NUM_NODES = getenv("PBS_NUM_NODES");
141 
142  int nodes = PBS_NUM_NODES == nullptr ? 1 : atoi(PBS_NUM_NODES);
143 
144  if(nodes == 0)
145  nodes = 1;
146 
147  int procsPerNode = numProcs / nodes;
148  int localRank = myId % procsPerNode;
149 
150  // Note, this will (probably) be overwritten by gpu-set-device calls...
151  if(deviceCount == 1 && localRank > 1) {
152  // Multi-process to one GPU!
153  gpuDev_ = 0;
154  } else if(procsPerNode > 1 && deviceCount > 1) {
155  if(localRank <= deviceCount) {
156  // setting multiple processes to multiple GPU's
157  gpuDev_ = localRank;
158  } else {
159  // More multiple processes than GPU's, distribute sort of evenly!
160  gpuDev_ = localRank % deviceCount;
161  }
162  } else {
163  // multiple GPU's, using one process
164  gpuDev_ = 0;
165  }
166 
167  std::cout << "MPI using CUDA device: " << gpuDev_ << std::endl;
168  cudaSetDevice(gpuDev_);
169 #endif
170 #endif
171 
172  // Fallthrough is useful for most models of GooFit subcommands
173  fallthrough();
174 
175 #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
176 #ifndef GOOFIT_MPI
177  add_option("--gpu-dev", gpuDev_, "GPU device to use", true)->group("GooFit");
178 #endif
179  add_flag("--show-gpus", show_gpus_, "Show the available GPU devices and exit")->group("GooFit");
180 #endif
181  auto quiet = add_flag("-q,--quiet", quiet_, "Reduce the verbosity of the Application")->group("GooFit");
182 
183  add_flag("--nosplash", splash_, "Do not print a splash")->group("GooFit")->excludes(quiet);
184 
185  set_config("--config", "config.ini", "An ini file with command line options in it")->group("GooFit");
186 
187  // Reset color on exit (but not control-c)
188  std::atexit([]() { std::cout << GooFit::reset; });
189 
190 #ifndef _MSC_VER
191  sigIntHandler.sa_handler = signal_handler;
192  sigemptyset(&sigIntHandler.sa_mask);
193  sigIntHandler.sa_flags = 0;
194  sigaction(SIGINT, &sigIntHandler, nullptr);
195 #endif
196 }
void signal_handler(int s)
will call the correct exit func, no unwinding of the stack though
Definition: Application.cpp:25
struct sigaction sigIntHandler
Handle control-c codes.
Definition: Application.h:52
constexpr rang::style const reset
Definition: Color.h:16

◆ Application() [2/2]

GooFit::Application::Application ( int  argc,
char **  argv 
)
inline

Shortcut for the lazy.

Definition at line 59 of file Application.h.

60  : Application("", argc, argv) {}
Application(std::string discription, int argc, char **argv)
Make a new Application.

◆ ~Application()

GooFit::Application::~Application ( )
overridedefault

Cleanup MPI if needed.

Referenced by exit(), and run().

Member Function Documentation

◆ exit()

int GooFit::Application::exit ( const CLI::Error &  e)

Exit.

Definition at line 216 of file Application.cpp.

References GooFit::blue, GooFit::red, GooFit::reset, and ~Application().

Referenced by run().

216  {
217 #ifdef GOOFIT_MPI
218  int myId;
219  MPI_Comm_rank(MPI_COMM_WORLD, &myId);
220 
221  if(myId > 0)
222  return e.get_exit_code();
223 
224 #endif
225  std::cout << (e.get_exit_code() == 0 ? blue : red);
226  int rval = CLI::App::exit(e);
227  std::cout << GooFit::reset;
228  return rval;
229 }
constexpr rang::fg const blue
Definition: Color.h:12
constexpr rang::fg const red
Definition: Color.h:9
constexpr rang::style const reset
Definition: Color.h:16

◆ get_device()

int GooFit::Application::get_device ( ) const
inline

Get the set GPU device.

Definition at line 63 of file Application.h.

References gpuDev_.

63 { return gpuDev_; }

◆ get_filename()

std::string GooFit::Application::get_filename ( const std::string &  input_str,
std::string  base = "" 
) const

Get a file from the current directory, looks up one and in the true current directory Base gives a relative path from the source directory

Definition at line 240 of file Application.cpp.

References argv_.

Referenced by getToyData(), makeBackgroundHistogram(), makeBkg2DalitzPdf(), makeBkg3Eff(), makeOverallSignal(), makeSigmaHists(), run(), runBackgroundDalitzFit(), runBackgroundSigmaFit(), runEfficiencyFit(), runGeneratedMCFit(), runToyFit(), and writeBackgroundHistograms().

240  {
241  // Run from current directory
242  if(CLI::ExistingFile(input_str).empty())
243  return input_str;
244 
245  // Run from a different directory
246  std::string prog_name{argv_[0]};
247  size_t loc = prog_name.rfind("/");
248  if(loc != std::string::npos) {
249  std::string cdir = prog_name.substr(0, loc);
250  std::string new_input{cdir + "/" + input_str};
251  if(CLI::ExistingFile(new_input).empty()) {
252  std::cout << "Found file at " << new_input << std::endl;
253  return new_input;
254  }
255  }
256 
257  // If all else fails, try to get file from source directory (if base is specified)
258  if(base.size() > 0) {
259  std::string new_input = std::string(GOOFIT_SOURCE_DIR) + "/" + base + "/" + input_str;
260  if(CLI::ExistingFile(new_input).empty()) {
261  std::cout << "Found file at " << new_input << std::endl;
262  return new_input;
263  }
264  }
265 
266  // Could not find file
267  throw GooFit::FileError(input_str);
268 }

◆ pre_callback()

void GooFit::Application::pre_callback ( )
override

Gets called in parse.

Definition at line 198 of file Application.cpp.

References gpuDev_, GooFit::print_goofit_info(), GooFit::print_splash(), quiet_, set_device(), and splash_.

Referenced by run().

198  {
199  set_device();
200 
201  if(!quiet_) {
202  if(!splash_)
203  print_splash();
205  }
206 }
void set_device() const
void print_splash()
Definition: Application.cpp:31
void print_goofit_info(int gpuDev_=0)
Print out information about GooFit.
Definition: Application.cpp:74

◆ run()

void GooFit::Application::run ( )
inline

simple run since argc and argv are stored

Definition at line 66 of file Application.h.

References exit(), get_filename(), pre_callback(), set_device(), and ~Application().

66 { parse(argc_, argv_); }

◆ set_device()

void GooFit::Application::set_device ( ) const

Call if the application might fork, otherwise automatic For example, if explicitly using omp

Definition at line 208 of file Application.cpp.

References gpuDev_.

Referenced by pre_callback(), and run().

208  {
209 #if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
210  if(gpuDev_ != 0) {
211  cudaSetDevice(gpuDev_);
212  }
213 #endif
214 }

Member Data Documentation

◆ argc_

int GooFit::Application::argc_
protected

Definition at line 48 of file Application.h.

Referenced by Application().

◆ argv_

char** GooFit::Application::argv_
protected

Definition at line 49 of file Application.h.

Referenced by Application(), and get_filename().

◆ gpuDev_

int GooFit::Application::gpuDev_ = 0
protected

Definition at line 44 of file Application.h.

Referenced by Application(), get_device(), pre_callback(), and set_device().

◆ quiet_

bool GooFit::Application::quiet_
protected

Definition at line 46 of file Application.h.

Referenced by Application(), and pre_callback().

◆ show_gpus_

bool GooFit::Application::show_gpus_
protected

Definition at line 45 of file Application.h.

Referenced by Application().

◆ sigIntHandler

struct sigaction GooFit::Application::sigIntHandler
protected

Handle control-c codes.

Definition at line 52 of file Application.h.

Referenced by Application().

◆ splash_

bool GooFit::Application::splash_
protected

Definition at line 47 of file Application.h.

Referenced by Application(), and pre_callback().


The documentation for this class was generated from the following files: