From bc881f0c7565ae251b1545c06f8f5a0f87943c3b Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Wed, 27 Apr 2016 08:11:30 +0200 Subject: [PATCH] moved CPU/GPU information collection from PFitter to musrfit. --- ChangeLog | 1 + src/classes/PFitter.cpp | 99 +++----------------------------------- src/include/PFitter.h | 5 +- src/musrfit.cpp | 103 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 112 insertions(+), 96 deletions(-) diff --git a/ChangeLog b/ChangeLog index d2ea0fd2..7c16e198 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ changes since 0.17.0 =================================== NEW 2016-03-08 added a theory translator for DKS NEW 2016-02-23 It is now possible to export the averaged data/Fourier +CHANGED 2016-04-27 moved CPU/GPU information collection from PFitter to musrfit. FIXED 2016-04-14 added missing DKS selector in GetPhaseOptRealFourier. changes since 0.16.0 diff --git a/src/classes/PFitter.cpp b/src/classes/PFitter.cpp index 5de9a082..f909cb89 100644 --- a/src/classes/PFitter.cpp +++ b/src/classes/PFitter.cpp @@ -32,9 +32,6 @@ #endif #include -#include -#include -#include #ifdef HAVE_GOMP #include @@ -83,9 +80,10 @@ using namespace std; * \param runInfo pointer of the msr-file handler * \param runListCollection pointer of the run list collection (pre-processed historgrams) * \param chisq_only flag: true=calculate chisq only (no fitting) + * \param hardwareInfo string containing CPU/GPU information */ -PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, Bool_t chisq_only) : - fChisqOnly(chisq_only), fRunInfo(runInfo), fRunListCollection(runListCollection) +PFitter::PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, Bool_t chisq_only, TString hardwareInfo) : + fChisqOnly(chisq_only), fHardwareInfo(hardwareInfo), fRunInfo(runInfo), fRunListCollection(runListCollection) { // initialize variables fDKSReady = false; @@ -1759,19 +1757,19 @@ Bool_t PFitter::ExecuteSave(Bool_t firstSave) // write CPU/GPU info switch (fDKSTag) { case DKS_CPU_OPENMP: - fout << endl << " CPU info : " << GetCpuInfo().Data(); + fout << endl << " CPU info : " << fHardwareInfo; fout << endl << " OpenMP" << endl; break; case DKS_CPU_OPENCL: - fout << endl << " CPU info : " << GetCpuInfo().Data(); + fout << endl << " CPU info : " << fHardwareInfo; fout << endl << " OpenCL" << endl; break; case DKS_GPU_CUDA: - fout << endl << " GPU info : " << GetGpuInfo().Data(); + fout << endl << " GPU info : " << fHardwareInfo; fout << endl << " Cuda" << endl; break; case DKS_GPU_OPENCL: - fout << endl << " GPU info : " << GetGpuInfo().Data(); + fout << endl << " GPU info : " << fHardwareInfo; fout << endl << " OpenCL" << endl; break; default: @@ -2123,89 +2121,6 @@ Double_t PFitter::MilliTime() return ((Double_t)now.tv_sec * 1.0e6 + (Double_t)now.tv_usec)/1.0e3; } -//-------------------------------------------------------------------------- -// GetCpuInfo (private) -//-------------------------------------------------------------------------- -/** - * @brief PFitter::GetCpuInfo - * @return - */ -TString PFitter::GetCpuInfo() -{ - TString cpuInfo = "??"; - - // find out if linux or Mac OS X - struct utsname sys_info; - - uname(&sys_info); - - if (strstr(sys_info.sysname, "Linux")) { - char result[128]; - strcpy(result, "??"); - - char line[128], str[128], *pos; - bool done = false; - ifstream fin("/proc/cpuinfo", ifstream::in); - while (fin.good() && !done) { - fin.getline(line, 128); - if (strstr(line, "model name")) { - pos = strstr(line, ":"); - strcpy(str, pos+2); - strncpy(result, str, sizeof(result)); - done = true; - } - } - fin.close(); - cpuInfo = result; - } else if (strstr(sys_info.sysname, "Linux")) { - system("sysctl -n machdep.cpu.brand_string >> _musrfit_cpu_info.txt"); - sleep(1); - - char line[128], result[128]; - ifstream fin("_musrfit_cpu_info.txt", ifstream::in); - while (fin.good()) { - fin.getline(line, 128); - strncat(result, line, sizeof(result) - strlen(result) - 1); - } - fin.close(); - system("rm _musrfit_cpu_info.txt"); - cpuInfo = result; - } - - return cpuInfo; -} - -//-------------------------------------------------------------------------- -// GetGpuInfo (private) -//-------------------------------------------------------------------------- -/** - * @brief PFitter::GetGpuInfo - * @return - */ -TString PFitter::GetGpuInfo() -{ - TString gpuInfo = "??"; - - system("nvidia-smi -L > _nv.txt"); - sleep(1); - - bool done=false; - char line[128]; - ifstream fin("_nv.txt", ifstream::in); - while (fin.good() && !done) { - fin.getline(line, 128); - if (strstr(line, "Tesla")) { - done = true; - } - } - fin.close(); - gpuInfo = line; - - system("rm _nv.txt"); - - return gpuInfo; -} - //------------------------------------------------------------------------------------------------- // end //------------------------------------------------------------------------------------------------- diff --git a/src/include/PFitter.h b/src/include/PFitter.h index a5a62982..a40af326 100644 --- a/src/include/PFitter.h +++ b/src/include/PFitter.h @@ -68,7 +68,7 @@ class PFitter { public: - PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, Bool_t chisq_only = false); + PFitter(PMsrHandler *runInfo, PRunListCollection *runListCollection, Bool_t chisq_only = false, TString hardwareInfo = TString("??")); virtual ~PFitter(); Bool_t IsValid() { return fIsValid; } @@ -85,6 +85,7 @@ class PFitter Bool_t fChisqOnly; ///< flag. true: calculate chi^2 only (no fitting). Bool_t fUseChi2; ///< flag. true: chi^2 fit. false: log-max-likelihood UInt_t fPrintLevel; ///< tag, showing the level of messages whished. 0=minimum, 1=standard, 2=maximum + TString fHardwareInfo; ///< string containing the CPU/GPU information. UInt_t fStrategy; ///< fitting strategy (see minuit2 manual). @@ -134,8 +135,6 @@ class PFitter Bool_t ExecuteSimplex(); Double_t MilliTime(); - TString GetCpuInfo(); - TString GetGpuInfo(); }; #endif // _PFITTER_H_ diff --git a/src/musrfit.cpp b/src/musrfit.cpp index a06b063c..72953c00 100644 --- a/src/musrfit.cpp +++ b/src/musrfit.cpp @@ -35,6 +35,8 @@ #include //#include #include +#include +#include #include #include @@ -119,6 +121,87 @@ void musrfit_syntax() cout << endl << endl; } +//-------------------------------------------------------------------------- +/** + *

extract CPU information from the system. + * + * @return the CPU information or ?? if this was not possible. + */ +TString musrfit_get_cpu_info() +{ + TString cpuInfo = "??"; + + // find out if linux or Mac OS X + struct utsname sys_info; + + uname(&sys_info); + + if (strstr(sys_info.sysname, "Linux")) { + char result[128]; + strcpy(result, "??"); + + char line[128], str[128], *pos; + bool done = false; + ifstream fin("/proc/cpuinfo", ifstream::in); + while (fin.good() && !done) { + fin.getline(line, 128); + if (strstr(line, "model name")) { + pos = strstr(line, ":"); + strcpy(str, pos+2); + strncpy(result, str, sizeof(result)); + done = true; + } + } + fin.close(); + cpuInfo = result; + } else if (strstr(sys_info.sysname, "Darwin")) { + system("sysctl -n machdep.cpu.brand_string >> _musrfit_cpu_info.txt"); + sleep(1); + + char line[128], result[128]; + ifstream fin("_musrfit_cpu_info.txt", ifstream::in); + while (fin.good()) { + fin.getline(line, 128); + strncat(result, line, sizeof(result) - strlen(result) - 1); + } + fin.close(); + system("rm _musrfit_cpu_info.txt"); + cpuInfo = result; + } + + return cpuInfo; +} + +//-------------------------------------------------------------------------- +/** + *

extract GPU information from the system. + * + * @return the GPU information or ?? if this was not possible. + */ +TString musrfit_get_gpu_info() +{ + TString gpuInfo = "??"; + + system("nvidia-smi -L > _nv.txt"); + sleep(1); + + bool done=false; + char line[128]; + ifstream fin("_nv.txt", ifstream::in); + while (fin.good() && !done) { + fin.getline(line, 128); + if (strstr(line, "Tesla")) { + done = true; + } + } + fin.close(); + gpuInfo = line; + + system("rm _nv.txt"); + + return gpuInfo; +} + //-------------------------------------------------------------------------- /** *

Writes the fitted data- and theory-set in ascii format to disc. @@ -634,6 +717,22 @@ int main(int argc, char *argv[]) return status; } + // get CPU/GPU information + UInt_t dksTag = msrHandler->GetDKSTag(); + TString hardwareInfo = TString("??"); + switch (dksTag) { + case DKS_CPU_OPENMP: + case DKS_CPU_OPENCL: + hardwareInfo = musrfit_get_cpu_info(); + break; + case DKS_GPU_CUDA: + case DKS_GPU_OPENCL: + hardwareInfo = musrfit_get_gpu_info(); + break; + default: + break; + } + // read all the necessary runs (raw data) PRunDataHandler *dataHandler; if (startupHandler) @@ -684,7 +783,7 @@ int main(int argc, char *argv[]) // do fitting PFitter *fitter = 0; if (success) { - fitter = new PFitter(msrHandler, runListCollection, chisq_only); + fitter = new PFitter(msrHandler, runListCollection, chisq_only, hardwareInfo); if (fitter->IsValid()) { fitter->DoFit(); if (!fitter->IsScanOnly()) @@ -692,6 +791,8 @@ int main(int argc, char *argv[]) } } + cout << "debug> after fit ..." << endl; + // write log file if (success && !chisq_only) { if (!fitter->IsScanOnly()) {