61feenableexcept (
unsigned int excepts)
66 unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
67 unsigned int old_excepts;
70 if ( fegetenv (&fenv) )
return -1;
71 old_excepts = fenv.__control & FE_ALL_EXCEPT;
74 fenv.__control &= ~new_excepts;
75 fenv.__mxcsr &= ~(new_excepts << 7);
77 iold_excepts = (int) old_excepts;
78 return ( fesetenv (&fenv) ? -1 : iold_excepts );
85#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
113 for(
int d=dims-1;d>=0;d--){
130 char ** itr = std::find(begin, end, option);
131 if (itr != end && ++itr != end) {
132 std::string payload(*itr);
135 return std::string(
"");
139 return std::find(begin, end, option) != end;
146 std::string delimiter(
",");
149 while ((pos = str.find(delimiter)) != std::string::npos) {
150 token = str.substr(0, pos);
151 vec.push_back(token);
152 str.erase(0, pos + delimiter.length());
155 vec.push_back(token);
159template<
class VectorInt>
163 std::stringstream ss(str);
167 if(std::ispunct(ss.peek()))
178 std::stringstream ss(str);
185 std::stringstream ss(str);
194 auto mpi =std::vector<int>({1,1,1,1});
195 auto latt=std::vector<int>({8,8,8,8});
209 std::vector<int> ompthreads(0);
211 std::cout <<
GridLogWarning <<
"'--threads' option used but Grid was"
212 <<
" not compiled with thread support" << std::endl;
216 assert(ompthreads.size()==1);
220 std::vector<int> gputhreads(0);
223 assert(gputhreads.size()==1);
235 assert(latt.size()==nd);
238 for(
int d=0;d<nd;d++){
244template<
class VectorInt>
246 int sz = vec_in.size();
247 std::vector<int>
vec(sz);
248 for(
int s=0;s<sz;s++)
vec[s] = vec_in[s];
249 std::ostringstream oss;
250 std::copy(
vec.begin(),
vec.end(),std::ostream_iterator<int>(oss,
" "));
264 std::cout <<std::endl;
265 std::cout <<
"__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
266 std::cout <<
"__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
267 std::cout <<
"__|_ | | | | | | | | | | | | _|__"<<std::endl;
268 std::cout <<
"__|_ _|__"<<std::endl;
269 std::cout <<
"__|_ GGGG RRRR III DDDD _|__"<<std::endl;
270 std::cout <<
"__|_ G R R I D D _|__"<<std::endl;
271 std::cout <<
"__|_ G R R I D D _|__"<<std::endl;
272 std::cout <<
"__|_ G GG RRRR I D D _|__"<<std::endl;
273 std::cout <<
"__|_ G G R R I D D _|__"<<std::endl;
274 std::cout <<
"__|_ GGGG R R III DDDD _|__"<<std::endl;
275 std::cout <<
"__|_ _|__"<<std::endl;
276 std::cout <<
"__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
277 std::cout <<
"__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
278 std::cout <<
" | | | | | | | | | | | | | | "<<std::endl;
279 std::cout << std::endl;
280 std::cout << std::endl;
281 std::cout <<
"Copyright (C) 2015 Peter Boyle, Azusa Yamaguchi, Guido Cossu, Antonin Portelli and other authors"<<std::endl;
282 std::cout << std::endl;
283 std::cout <<
"This program is free software; you can redistribute it and/or modify"<<std::endl;
284 std::cout <<
"it under the terms of the GNU General Public License as published by"<<std::endl;
285 std::cout <<
"the Free Software Foundation; either version 2 of the License, or"<<std::endl;
286 std::cout <<
"(at your option) any later version."<<std::endl;
287 std::cout << std::endl;
288 std::cout <<
"This program is distributed in the hope that it will be useful,"<<std::endl;
289 std::cout <<
"but WITHOUT ANY WARRANTY; without even the implied warranty of"<<std::endl;
290 std::cout <<
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"<<std::endl;
291 std::cout <<
"GNU General Public License for more details."<<std::endl;
294#define _GRID_BUILD_STR(x) #x
295#define GRID_BUILD_STR(x) _GRID_BUILD_STR(x)
296 std::cout <<
"Build " << GRID_BUILD_STR(GRID_BUILD_REF) << std::endl;
298 std::cout << std::endl;
299 std::cout << std::setprecision(9);
384 std::cout <<
"Option --comms-overlap currently not supported on QPACE4. Exiting." << std::endl;
418 std::ostringstream fname;
419 fname<<
"Grid.stdout.";
421 fp=freopen(fname.str().c_str(),
"w",stdout);
422 assert(fp!=(FILE *)NULL);
424 std::ostringstream ename;
425 ename<<
"Grid.stderr.";
427 fp=freopen(ename.str().c_str(),
"w",stderr);
428 assert(fp!=(FILE *)NULL);
436 std::cout <<
GridLogMessage <<
"================================================ "<<std::endl;
437 std::cout <<
GridLogMessage <<
"MPI is initialised and logging filters activated "<<std::endl;
438 std::cout <<
GridLogMessage <<
"================================================ "<<std::endl;
445 info = localtime(&mytime);
446 strftime(buffer,
sizeof(buffer),
"%Y-%m-%d %H:%M:%S", info);
447 std::cout <<
GridLogMessage <<
"This rank is running on host "<<
hostname<<
" at local time "<<buffer<<std::endl;
455 std::cout <<
GridLogMessage <<
"Mapped stencil comms buffers as MAP_HUGETLB "<<std::endl;
471 FILE *f = fopen(
"/proc/self/maps",
"r");
474 while (fgets(line,
sizeof(line), f)) {
475 if (strstr(line,
"r-xp")) {
477 uint32_t major, minor, inode;
478 uint64_t start,end,offset;
480 sscanf(line,
"%lx-%lx r-xp %lx %x:%x %d %s",
482 &major,&minor,&inode,path);
486 region.
name = std::string(path);
488 dlMap.push_back(region);
495 std::cout <<
GridLogMessage <<
"================================================ "<<std::endl;
496 std::cout <<
GridLogMessage<<
" Dynamic library map: " <<std::endl;
497 std::cout <<
GridLogMessage <<
"================================================ "<<std::endl;
498 for(
int r=0;r<
dlMap.size();r++){
499 auto region =
dlMap[r];
500 std::cout <<
GridLogMessage<<
" "<<region.name<<std::hex<<region.start<<
"-"<<region.end<<
" sz "<<region.size<<std::dec<<std::endl;
502 std::cout <<
GridLogMessage <<
"================================================ "<<std::endl;
509 std::vector<std::string> logstreams;
510 std::string defaultLog(
"Error,Warning,Message");
530 std::cout<<
GridLogMessage<<
" --mpi n.n.n.n : default MPI decomposition"<<std::endl;
531 std::cout<<
GridLogMessage<<
" --threads n : default number of OMP threads"<<std::endl;
532 std::cout<<
GridLogMessage<<
" --grid n.n.n.n : default Grid size"<<std::endl;
533 std::cout<<
GridLogMessage<<
" --shm M : allocate M megabytes of shared memory for comms"<<std::endl;
534 std::cout<<
GridLogMessage<<
" --shm-mpi 0|1 : Force MPI usage under multi-rank per node "<<std::endl;
535 std::cout<<
GridLogMessage<<
" --shm-hugepages : use explicit huge pages in mmap call "<<std::endl;
536 std::cout<<
GridLogMessage<<
" --device-mem M : Size of device software cache for lattice fields (MB) "<<std::endl;
540 std::cout<<
GridLogMessage<<
" --log list : comma separated list from Error,Warning,Message,Performance,Iterative,Integrator,Debug,Colours"<<std::endl;
541 std::cout<<
GridLogMessage<<
" --notimestamp : suppress millisecond resolution stamps"<<std::endl;
542 std::cout<<
GridLogMessage<<
" --decomposition : report on default omp,mpi and simd decomposition"<<std::endl;
544 std::cout<<
GridLogMessage<<
" --dylib-map : print dynamic library map, useful for interpreting signal backtraces "<<std::endl;
545 std::cout<<
GridLogMessage<<
" --heartbeat : periodic itimer wakeup (interrupts stuck system calls!) "<<std::endl;
546 std::cout<<
GridLogMessage<<
" --signal-delay n : pause for n seconds after signal handling (useful to get ALL nodes in stuck state) "<<std::endl;
547 std::cout<<
GridLogMessage<<
" --debug-stdout : print stdout from EVERY node to file Grid.stdout/err.rank "<<std::endl;
548 std::cout<<
GridLogMessage<<
" --debug-signals : catch sigsegv and print a blame report, handle SIGHUP with a backtrace to stderr"<<std::endl;
549 std::cout<<
GridLogMessage<<
" --debug-heartbeat : periodically report backtrace "<<std::endl;
550 std::cout<<
GridLogMessage<<
" --debug-mem : print Grid allocator activity"<<std::endl;
554 std::cout<<
GridLogMessage<<
" --comms-overlap : Overlap comms with compute "<<std::endl;
556 std::cout<<
GridLogMessage<<
" --dslash-generic: Wilson kernel for generic Nc"<<std::endl;
557 std::cout<<
GridLogMessage<<
" --dslash-unroll : Wilson kernel for Nc=3"<<std::endl;
558 std::cout<<
GridLogMessage<<
" --dslash-asm : Wilson kernel for AVX512"<<std::endl;
600 std::cout <<
GridLogMessage <<
" Enabling flight recorder " <<std::endl;
608 std::cout<<
GridLogMessage<<
"Grid Default Decomposition patterns\n";
622 std::cout<<
GridLogMessage<<
"*******************************************"<<std::endl;
623 std::cout<<
GridLogMessage<<
"******* Grid Finalize ******"<<std::endl;
624 std::cout<<
GridLogMessage<<
"*******************************************"<<std::endl;
626#if defined (GRID_COMMS_MPI) || defined (GRID_COMMS_MPI3) || defined (GRID_COMMS_MPIT)
627 MPI_Barrier(MPI_COMM_WORLD);
631#if defined (GRID_COMMS_SHMEM)
645#define SIGLOG(A) ::write(fileno_stderr,A,strlen(A));
649 const char *digits[] = {
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f" };
650 if ( dig>=0 && dig< 16){
658#define DIGIT(DIV) dig = (A/DIV)%10 ; if(dig|nz) sig_print_dig(dig); nz = nz|dig;
675#define NIBBLE(A) dig = A ; if(dig|nz) sig_print_dig(dig); nz = nz|dig;
705 SIGLOG(
"Signal handler on host ");
710 SIGLOG(
"FlightRecorder step ");
725 ucontext_t *uc= (ucontext_t *)ptr;
734 if (!unw_init_local(&cursor, uc) ) {
736 SIGLOG(
" frame IP function\n");
743 unw_get_reg(&cursor, UNW_REG_IP, &ip);
747 for(
int r=0;r<
dlMap.size();r++){
758 ret = unw_step(&cursor);
780 SIGLOG(
"Adding extra signal delay ");
803 struct sigaction sa_ping;
805 sigemptyset (&sa_ping.sa_mask);
807 sa_ping.sa_flags = SA_SIGINFO;
808 sigaction(SIGALRM,&sa_ping,NULL);
811 struct itimerval it_val;
812 it_val.it_value.tv_sec = 10;
813 it_val.it_value.tv_usec = 0;
814 it_val.it_interval = it_val.it_value;
815 setitimer(ITIMER_REAL, &it_val, NULL);
819 struct sigaction sa_ping;
821 sigemptyset (&sa_ping.sa_mask);
823 sa_ping.sa_flags = SA_SIGINFO;
824 sigaction(SIGALRM,&sa_ping,NULL);
827 struct itimerval it_val;
828 it_val.it_value.tv_sec = 10;
829 it_val.it_value.tv_usec = 1000;
830 it_val.it_interval = it_val.it_value;
831 setitimer(ITIMER_REAL, &it_val, NULL);
841 sigemptyset (&sa.sa_mask);
843 sa.sa_flags = SA_SIGINFO;
844 sigaction(SIGTRAP,&sa,NULL);
845 sigaction(SIGILL,&sa,NULL);
847 sigaction(SIGSEGV,&sa,NULL);
848 sigaction(SIGBUS,&sa,NULL);
849 feenableexcept( FE_INVALID|FE_OVERFLOW|FE_DIVBYZERO);
850 sigaction(SIGFPE,&sa,NULL);
854 struct sigaction sa_ping;
855 sigemptyset (&sa_ping.sa_mask);
857 sa_ping.sa_flags = SA_SIGINFO;
858 sigaction(SIGHUP,&sa_ping,NULL);
void acceleratorInit(void)
uint32_t acceleratorThreads(void)
AcceleratorVector< int, MaxDims > Coordinate
Grid_simd< complex< float >, SIMD_Ftype > vComplexF
Grid_simd< float, SIMD_Ftype > vRealF
Grid_simd< complex< double >, SIMD_Dtype > vComplexD
Grid_simd< double, SIMD_Dtype > vRealD
bool GridCmdOptionExists(char **begin, char **end, const std::string &option)
char hostname[HOST_NAME_MAX+1]
void Grid_heartbeat_signal_handler(int sig, siginfo_t *si, void *ptr)
char * GridHostname(void)
static Coordinate Grid_default_latt
static int Grid_is_initialised
void sig_print_dig(uint32_t dig)
static MemoryStats dbgMemStats
void Grid_exit_handler(void)
void Grid_empty_signal_handler(int sig, siginfo_t *si, void *ptr)
void GridCmdOptionFloat(std::string &str, double &val)
const Coordinate GridDefaultSimd(int dims, int nsimd)
void Grid_debug_handler_init(void)
void Grid_init(int *argc, char ***argv)
void GridCmdOptionInt(std::string &str, int &val)
void Grid_heartbeat(void)
void Grid_debug_heartbeat(void)
void sig_print_uint(uint32_t A)
void sig_print_hex(uint64_t A)
const Coordinate & GridDefaultLatt(void)
void GridCmdOptionIntVector(const std::string &str, VectorInt &vec)
static Coordinate Grid_default_mpi
std::vector< dlRegion > dlMap
const Coordinate & GridDefaultMpi(void)
void Grid_fatal_signal_handler(int sig, siginfo_t *si, void *ptr)
std::string GridCmdVectorIntToString(const VectorInt &vec_in)
void GridCmdOptionCSL(std::string str, std::vector< std::string > &vec)
void Grid_usr_signal_handler(int sig, siginfo_t *si, void *ptr)
void Grid_generic_handler(int sig, siginfo_t *si, void *ptr)
void GridParseLayout(char **argv, int argc, Coordinate &latt_c, Coordinate &mpi_c)
std::string GridCmdOptionPayload(char **begin, char **end, const std::string &option)
void GridLogTimestamp(int on)
void Grid_quiesce_nodes(void)
void GridLogConfigure(std::vector< std::string > &logstreams)
void Grid_unquiesce_nodes(void)
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
GridLogger GridLogWarning(1, "Warning", GridLogColours, "YELLOW")
void * Grid_backtrace_buffer[_NBACKTRACE]
#define NAMESPACE_BEGIN(A)
accelerator_inline void resize(size_type sz)
static void Init(int *argc, char ***argv)
static int RankWorld(void)
static void BarrierWorld(void)
static const char * StepName
static int32_t StepLoggingCounter
static int PrintEntireLog
static void SetLoggingMode(LoggingMode_t mode)
static int ChecksumCommsSend
static uint64_t MAX_MPI_SHM_BYTES
static void SetMaxThreads(void)
static int GetThreads(void)
static void SetCores(int cr)
static void SetThreads(int thr)
static accelerator_inline constexpr int Nsimd(void)
static GridStopWatch GlobalStopWatch
static void InitMessage(void)
static uint64_t DeviceMaxBytes
static MemoryStats * stats