2017-02-07 05:57:55 +00:00
|
|
|
/*************************************************************************************
|
2016-01-02 14:51:32 +00:00
|
|
|
|
2017-03-21 07:11:35 +00:00
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
2016-01-02 14:51:32 +00:00
|
|
|
|
|
|
|
Source file: ./lib/Init.cc
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <peterboyle@MacBook-Pro.local>
|
|
|
|
Author: paboyle <paboyle@ph.ed.ac.uk>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
2018-01-12 23:29:22 +00:00
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2015-03-04 13:43:19 +00:00
|
|
|
/****************************************************************************/
|
2015-05-11 18:59:03 +01:00
|
|
|
/* pab: Signal magic. Processor state dump is x86-64 specific */
|
2015-03-04 13:43:19 +00:00
|
|
|
/****************************************************************************/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
2017-03-21 07:11:35 +00:00
|
|
|
#include <sys/stat.h>
|
2015-03-04 13:43:19 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <signal.h>
|
2015-04-23 20:42:30 +01:00
|
|
|
#include <iostream>
|
2015-05-23 09:30:28 +01:00
|
|
|
#include <iterator>
|
2015-05-11 12:43:10 +01:00
|
|
|
#include <algorithm>
|
2015-05-20 09:32:46 +01:00
|
|
|
#include <iterator>
|
2016-08-31 00:23:28 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <memory>
|
|
|
|
|
2017-02-22 18:09:33 +00:00
|
|
|
#include <Grid/Grid.h>
|
|
|
|
|
2017-05-11 10:20:24 +01:00
|
|
|
#include <Grid/util/CompilerCompatible.h>
|
|
|
|
|
2015-03-04 13:43:19 +00:00
|
|
|
|
2016-09-26 10:09:13 +01:00
|
|
|
#include <fenv.h>
|
|
|
|
#ifdef __APPLE__
|
|
|
|
static int
|
|
|
|
feenableexcept (unsigned int excepts)
|
|
|
|
{
|
|
|
|
static fenv_t fenv;
|
2018-01-24 13:09:53 +00:00
|
|
|
unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
|
|
|
|
unsigned int old_excepts; // previous masks
|
|
|
|
int iold_excepts; // previous masks
|
2016-09-26 10:09:13 +01:00
|
|
|
|
|
|
|
if ( fegetenv (&fenv) ) return -1;
|
|
|
|
old_excepts = fenv.__control & FE_ALL_EXCEPT;
|
|
|
|
|
|
|
|
// unmask
|
|
|
|
fenv.__control &= ~new_excepts;
|
|
|
|
fenv.__mxcsr &= ~(new_excepts << 7);
|
|
|
|
|
2018-01-24 13:09:53 +00:00
|
|
|
iold_excepts = (int) old_excepts;
|
|
|
|
return ( fesetenv (&fenv) ? -1 : iold_excepts );
|
2016-09-26 10:09:13 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-12 23:29:22 +00:00
|
|
|
NAMESPACE_BEGIN(Grid);
|
2016-08-31 00:23:28 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Convenience functions to access stadard command line arg
|
|
|
|
// driven parallelism controls
|
|
|
|
//////////////////////////////////////////////////////
|
2018-02-24 22:25:39 +00:00
|
|
|
static Coordinate Grid_default_latt;
|
|
|
|
static Coordinate Grid_default_mpi;
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2015-11-06 11:46:21 +00:00
|
|
|
int GridThread::_threads =1;
|
|
|
|
int GridThread::_hyperthreads=1;
|
|
|
|
int GridThread::_cores=1;
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2018-02-24 22:25:39 +00:00
|
|
|
const Coordinate &GridDefaultLatt(void) {return Grid_default_latt;};
|
|
|
|
const Coordinate &GridDefaultMpi(void) {return Grid_default_mpi;};
|
|
|
|
const Coordinate GridDefaultSimd(int dims,int nsimd)
|
2015-07-23 17:31:13 +01:00
|
|
|
{
|
2018-02-24 22:25:39 +00:00
|
|
|
Coordinate layout(dims);
|
2018-01-12 23:29:22 +00:00
|
|
|
int nn=nsimd;
|
|
|
|
for(int d=dims-1;d>=0;d--){
|
|
|
|
if ( nn>=2) {
|
|
|
|
layout[d]=2;
|
|
|
|
nn/=2;
|
|
|
|
} else {
|
|
|
|
layout[d]=1;
|
2015-05-12 20:41:44 +01:00
|
|
|
}
|
2018-01-12 23:29:22 +00:00
|
|
|
}
|
|
|
|
assert(nn==1);
|
|
|
|
return layout;
|
2015-07-23 17:31:13 +01:00
|
|
|
}
|
2017-03-21 07:11:35 +00:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Command line parsing assist for stock controls
|
|
|
|
////////////////////////////////////////////////////////////
|
2015-05-11 12:43:10 +01:00
|
|
|
std::string GridCmdOptionPayload(char ** begin, char ** end, const std::string & option)
|
|
|
|
{
|
|
|
|
char ** itr = std::find(begin, end, option);
|
|
|
|
if (itr != end && ++itr != end) {
|
|
|
|
std::string payload(*itr);
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
return std::string("");
|
|
|
|
}
|
|
|
|
bool GridCmdOptionExists(char** begin, char** end, const std::string& option)
|
|
|
|
{
|
|
|
|
return std::find(begin, end, option) != end;
|
|
|
|
}
|
2018-01-12 23:29:22 +00:00
|
|
|
// Comma separated list
|
2015-07-23 17:31:13 +01:00
|
|
|
void GridCmdOptionCSL(std::string str,std::vector<std::string> & vec)
|
|
|
|
{
|
|
|
|
size_t pos = 0;
|
|
|
|
std::string token;
|
|
|
|
std::string delimiter(",");
|
|
|
|
|
|
|
|
vec.resize(0);
|
|
|
|
while ((pos = str.find(delimiter)) != std::string::npos) {
|
|
|
|
token = str.substr(0, pos);
|
|
|
|
vec.push_back(token);
|
|
|
|
str.erase(0, pos + delimiter.length());
|
|
|
|
}
|
|
|
|
token = str;
|
|
|
|
vec.push_back(token);
|
|
|
|
return;
|
|
|
|
}
|
2015-05-11 12:43:10 +01:00
|
|
|
|
2018-02-24 22:25:39 +00:00
|
|
|
template<class VectorInt>
|
|
|
|
void GridCmdOptionIntVector(std::string &str,VectorInt & vec)
|
2015-05-11 12:43:10 +01:00
|
|
|
{
|
|
|
|
vec.resize(0);
|
|
|
|
std::stringstream ss(str);
|
|
|
|
int i;
|
|
|
|
while (ss >> i){
|
|
|
|
vec.push_back(i);
|
2015-05-11 18:59:03 +01:00
|
|
|
if(std::ispunct(ss.peek()))
|
2015-05-11 12:43:10 +01:00
|
|
|
ss.ignore();
|
2017-03-21 07:11:35 +00:00
|
|
|
}
|
2015-05-11 12:43:10 +01:00
|
|
|
return;
|
2015-03-04 13:43:19 +00:00
|
|
|
}
|
2015-05-11 12:43:10 +01:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
void GridCmdOptionInt(std::string &str,int & val)
|
|
|
|
{
|
|
|
|
std::stringstream ss(str);
|
|
|
|
ss>>val;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2015-05-11 14:36:48 +01:00
|
|
|
void GridParseLayout(char **argv,int argc,
|
2018-02-24 22:25:39 +00:00
|
|
|
Coordinate &latt_c,
|
|
|
|
Coordinate &mpi_c)
|
2015-05-11 12:43:10 +01:00
|
|
|
{
|
2018-02-24 22:25:39 +00:00
|
|
|
auto mpi =std::vector<int>({1,1,1,1});
|
|
|
|
auto latt=std::vector<int>({8,8,8,8});
|
2015-05-11 14:36:48 +01:00
|
|
|
|
2015-05-11 18:59:03 +01:00
|
|
|
GridThread::SetMaxThreads();
|
|
|
|
|
2015-05-11 12:43:10 +01:00
|
|
|
std::string arg;
|
2015-05-11 14:36:48 +01:00
|
|
|
if( GridCmdOptionExists(argv,argv+argc,"--mpi") ){
|
|
|
|
arg = GridCmdOptionPayload(argv,argv+argc,"--mpi");
|
2015-05-11 12:43:10 +01:00
|
|
|
GridCmdOptionIntVector(arg,mpi);
|
|
|
|
}
|
2015-05-11 14:36:48 +01:00
|
|
|
if( GridCmdOptionExists(argv,argv+argc,"--grid") ){
|
|
|
|
arg= GridCmdOptionPayload(argv,argv+argc,"--grid");
|
2015-05-11 12:43:10 +01:00
|
|
|
GridCmdOptionIntVector(arg,latt);
|
|
|
|
}
|
2015-11-06 11:46:21 +00:00
|
|
|
if( GridCmdOptionExists(argv,argv+argc,"--threads") ){
|
2015-05-11 18:59:03 +01:00
|
|
|
std::vector<int> ompthreads(0);
|
2016-05-11 15:21:29 +01:00
|
|
|
#ifndef GRID_OMP
|
|
|
|
std::cout << GridLogWarning << "'--threads' option used but Grid was"
|
|
|
|
<< " not compiled with thread support" << std::endl;
|
|
|
|
#endif
|
2015-11-06 11:46:21 +00:00
|
|
|
arg= GridCmdOptionPayload(argv,argv+argc,"--threads");
|
2015-05-11 18:59:03 +01:00
|
|
|
GridCmdOptionIntVector(arg,ompthreads);
|
|
|
|
assert(ompthreads.size()==1);
|
|
|
|
GridThread::SetThreads(ompthreads[0]);
|
|
|
|
}
|
2015-11-06 11:46:21 +00:00
|
|
|
if( GridCmdOptionExists(argv,argv+argc,"--cores") ){
|
2016-11-02 08:07:09 +00:00
|
|
|
int cores;
|
2015-11-06 11:46:21 +00:00
|
|
|
arg= GridCmdOptionPayload(argv,argv+argc,"--cores");
|
2016-11-02 08:07:09 +00:00
|
|
|
GridCmdOptionInt(arg,cores);
|
|
|
|
GridThread::SetCores(cores);
|
2015-11-06 11:46:21 +00:00
|
|
|
}
|
2018-02-24 22:25:39 +00:00
|
|
|
// Copy back into coordinate format
|
|
|
|
int nd = mpi.size();
|
|
|
|
assert(latt.size()==nd);
|
|
|
|
latt_c.resize(nd);
|
|
|
|
mpi_c.resize(nd);
|
|
|
|
for(int d=0;d<nd;d++){
|
|
|
|
latt_c[d] = latt[d];
|
|
|
|
mpi_c[d] = mpi[d];
|
|
|
|
}
|
2015-05-11 12:43:10 +01:00
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2018-02-24 22:25:39 +00:00
|
|
|
template<class VectorInt>
|
|
|
|
std::string GridCmdVectorIntToString(const VectorInt & vec_in){
|
|
|
|
int sz = vec_in.size();
|
|
|
|
std::vector<int> vec(sz);
|
|
|
|
for(int s=0;s<sz;s++) vec[s] = vec_in[s];
|
2015-05-19 14:54:42 +01:00
|
|
|
std::ostringstream oss;
|
|
|
|
std::copy(vec.begin(), vec.end(),std::ostream_iterator<int>(oss, " "));
|
|
|
|
return oss.str();
|
|
|
|
}
|
2015-07-23 17:31:13 +01:00
|
|
|
/////////////////////////////////////////////////////////
|
2016-11-02 08:07:09 +00:00
|
|
|
// Reinit guard
|
2015-07-23 17:31:13 +01:00
|
|
|
/////////////////////////////////////////////////////////
|
2017-12-07 13:40:58 +00:00
|
|
|
static MemoryStats dbgMemStats;
|
2018-01-24 13:09:53 +00:00
|
|
|
static int Grid_is_initialised;
|
2016-10-24 17:30:43 +01:00
|
|
|
|
2018-03-19 11:12:12 +00:00
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
// Reinit guard
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
#ifdef GRID_NVCC
|
|
|
|
void GridGpuInit(void)
|
|
|
|
{
|
|
|
|
int nDevices;
|
|
|
|
|
|
|
|
cudaGetDeviceCount(&nDevices);
|
|
|
|
for (int i = 0; i < nDevices; i++) {
|
|
|
|
cudaDeviceProp prop;
|
|
|
|
cudaGetDeviceProperties(&prop, i);
|
|
|
|
printf("Device Number: %d\n", i);
|
|
|
|
printf(" Device name: %s\n", prop.name);
|
|
|
|
printf(" Memory Clock Rate (KHz): %d\n",
|
|
|
|
prop.memoryClockRate);
|
|
|
|
printf(" Memory Bus Width (bits): %d\n",
|
|
|
|
prop.memoryBusWidth);
|
|
|
|
printf(" Peak Memory Bandwidth (GB/s): %f\n\n",
|
|
|
|
2.0*prop.memoryClockRate*(prop.memoryBusWidth/8)/1.0e6);
|
|
|
|
|
|
|
|
#define GPU_PROP_FMT(canMapHostMemory,FMT) printf(" " #canMapHostMemory ": " FMT" \n",prop.canMapHostMemory);
|
|
|
|
#define GPU_PROP(canMapHostMemory) printf(" " #canMapHostMemory ": %d \n",prop.canMapHostMemory);
|
|
|
|
GPU_PROP(canMapHostMemory);
|
|
|
|
GPU_PROP(canUseHostPointerForRegisteredMem);
|
|
|
|
GPU_PROP(globalL1CacheSupported);
|
|
|
|
GPU_PROP(isMultiGpuBoard);
|
|
|
|
GPU_PROP(kernelExecTimeoutEnabled);
|
|
|
|
GPU_PROP(l2CacheSize);
|
|
|
|
GPU_PROP(managedMemory);
|
|
|
|
GPU_PROP(pageableMemoryAccess);
|
|
|
|
GPU_PROP(regsPerMultiprocessor);
|
|
|
|
GPU_PROP_FMT(sharedMemPerBlock,"%lx");
|
|
|
|
GPU_PROP_FMT(sharedMemPerMultiprocessor,"%lx");
|
|
|
|
GPU_PROP(singleToDoublePrecisionPerfRatio);
|
|
|
|
GPU_PROP(unifiedAddressing);
|
|
|
|
GPU_PROP(warpSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-11 18:59:03 +01:00
|
|
|
void Grid_init(int *argc,char ***argv)
|
|
|
|
{
|
2018-01-24 13:09:53 +00:00
|
|
|
assert(Grid_is_initialised == 0);
|
|
|
|
|
2017-10-13 13:23:07 +01:00
|
|
|
GridLogger::GlobalStopWatch.Start();
|
2016-10-24 17:30:43 +01:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
std::string arg;
|
|
|
|
|
|
|
|
////////////////////////////////////
|
|
|
|
// Shared memory block size
|
|
|
|
////////////////////////////////////
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--shm") ){
|
|
|
|
int MB;
|
|
|
|
arg= GridCmdOptionPayload(*argv,*argv+*argc,"--shm");
|
|
|
|
GridCmdOptionInt(arg,MB);
|
2017-08-31 10:42:35 +01:00
|
|
|
uint64_t MB64 = MB;
|
2018-01-08 11:28:52 +00:00
|
|
|
GlobalSharedMemory::MAX_MPI_SHM_BYTES = MB64*1024LL*1024LL;
|
2016-11-02 08:07:09 +00:00
|
|
|
}
|
|
|
|
|
2017-08-20 01:10:50 +01:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--shm-hugepages") ){
|
2018-01-08 11:28:52 +00:00
|
|
|
GlobalSharedMemory::Hugepages = 1;
|
2017-08-20 01:10:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-07 05:57:55 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--debug-signals") ){
|
|
|
|
Grid_debug_handler_init();
|
|
|
|
}
|
|
|
|
|
2016-02-14 20:24:38 +00:00
|
|
|
CartesianCommunicator::Init(argc,argv);
|
|
|
|
|
2017-02-07 05:57:55 +00:00
|
|
|
if( !GridCmdOptionExists(*argv,*argv+*argc,"--debug-stdout") ){
|
|
|
|
Grid_quiesce_nodes();
|
|
|
|
} else {
|
2017-05-06 16:38:58 +01:00
|
|
|
FILE *fp;
|
2017-02-07 05:57:55 +00:00
|
|
|
std::ostringstream fname;
|
|
|
|
fname<<"Grid.stdout.";
|
|
|
|
fname<<CartesianCommunicator::RankWorld();
|
2017-05-06 16:38:58 +01:00
|
|
|
fp=freopen(fname.str().c_str(),"w",stdout);
|
|
|
|
assert(fp!=(FILE *)NULL);
|
2017-10-09 23:18:48 +01:00
|
|
|
|
|
|
|
std::ostringstream ename;
|
|
|
|
ename<<"Grid.stderr.";
|
|
|
|
ename<<CartesianCommunicator::RankWorld();
|
|
|
|
fp=freopen(ename.str().c_str(),"w",stderr);
|
|
|
|
assert(fp!=(FILE *)NULL);
|
2017-02-07 05:57:55 +00:00
|
|
|
}
|
|
|
|
|
2017-12-07 13:40:58 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--debug-mem") ){
|
|
|
|
MemoryProfiler::debug = true;
|
|
|
|
MemoryProfiler::stats = &dbgMemStats;
|
|
|
|
}
|
|
|
|
|
2017-02-07 05:57:55 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Banner
|
|
|
|
////////////////////////////////////
|
|
|
|
if ( CartesianCommunicator::RankWorld() == 0 ) {
|
|
|
|
std::cout <<std::endl;
|
|
|
|
std::cout << "__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
|
|
|
|
std::cout << "__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
|
|
|
|
std::cout << "__|_ | | | | | | | | | | | | _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ GGGG RRRR III DDDD _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ G R R I D D _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ G R R I D D _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ G GG RRRR I D D _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ G G R R I D D _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ GGGG R R III DDDD _|__"<<std::endl;
|
|
|
|
std::cout << "__|_ _|__"<<std::endl;
|
|
|
|
std::cout << "__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
|
|
|
|
std::cout << "__|__|__|__|__|__|__|__|__|__|__|__|__|__|__"<<std::endl;
|
|
|
|
std::cout << " | | | | | | | | | | | | | | "<<std::endl;
|
|
|
|
std::cout << std::endl;
|
|
|
|
std::cout << std::endl;
|
|
|
|
std::cout << "Copyright (C) 2015 Peter Boyle, Azusa Yamaguchi, Guido Cossu, Antonin Portelli and other authors"<<std::endl;
|
|
|
|
std::cout << std::endl;
|
|
|
|
std::cout << "This program is free software; you can redistribute it and/or modify"<<std::endl;
|
|
|
|
std::cout << "it under the terms of the GNU General Public License as published by"<<std::endl;
|
|
|
|
std::cout << "the Free Software Foundation; either version 2 of the License, or"<<std::endl;
|
|
|
|
std::cout << "(at your option) any later version."<<std::endl;
|
|
|
|
std::cout << std::endl;
|
|
|
|
std::cout << "This program is distributed in the hope that it will be useful,"<<std::endl;
|
|
|
|
std::cout << "but WITHOUT ANY WARRANTY; without even the implied warranty of"<<std::endl;
|
|
|
|
std::cout << "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"<<std::endl;
|
|
|
|
std::cout << "GNU General Public License for more details."<<std::endl;
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
|
2018-03-19 11:12:12 +00:00
|
|
|
#ifdef GRID_NVCC
|
|
|
|
GridGpuInit();
|
|
|
|
#endif
|
2017-02-07 05:57:55 +00:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Logging
|
|
|
|
////////////////////////////////////
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::vector<std::string> logstreams;
|
|
|
|
std::string defaultLog("Error,Warning,Message,Performance");
|
|
|
|
GridCmdOptionCSL(defaultLog,logstreams);
|
|
|
|
GridLogConfigure(logstreams);
|
|
|
|
|
|
|
|
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--log") ){
|
|
|
|
arg = GridCmdOptionPayload(*argv,*argv+*argc,"--log");
|
|
|
|
GridCmdOptionCSL(arg,logstreams);
|
|
|
|
GridLogConfigure(logstreams);
|
2015-05-19 14:54:42 +01:00
|
|
|
}
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Help message
|
|
|
|
////////////////////////////////////
|
2016-10-24 17:30:43 +01:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--help") ){
|
|
|
|
std::cout<<GridLogMessage<<" --help : this message"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"Geometry:"<<std::endl;
|
2017-02-10 23:22:31 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<" --mpi n.n.n.n : default MPI decomposition"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --threads n : default number of OMP threads"<<std::endl;
|
2017-03-21 07:11:35 +00:00
|
|
|
std::cout<<GridLogMessage<<" --grid n.n.n.n : default Grid size"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --shm M : allocate M megabytes of shared memory for comms"<<std::endl;
|
2017-08-20 01:10:50 +01:00
|
|
|
std::cout<<GridLogMessage<<" --shm-hugepages : use explicit huge pages in mmap call "<<std::endl;
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"Verbose and debug:"<<std::endl;
|
2017-02-10 23:22:31 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --log list : comma separated list from Error,Warning,Message,Performance,Iterative,Integrator,Debug,Colours"<<std::endl;
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<" --decomposition : report on default omp,mpi and simd decomposition"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --debug-signals : catch sigsegv and print a blame report"<<std::endl;
|
2017-03-21 07:11:35 +00:00
|
|
|
std::cout<<GridLogMessage<<" --debug-stdout : print stdout from EVERY node"<<std::endl;
|
2017-12-07 13:40:58 +00:00
|
|
|
std::cout<<GridLogMessage<<" --debug-mem : print Grid allocator activity"<<std::endl;
|
2017-03-21 07:11:35 +00:00
|
|
|
std::cout<<GridLogMessage<<" --notimestamp : suppress millisecond resolution stamps"<<std::endl;
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"Performance:"<<std::endl;
|
2017-02-10 23:22:31 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
2017-04-15 08:54:11 +01:00
|
|
|
std::cout<<GridLogMessage<<" --comms-concurrent : Asynchronous MPI calls; several dirs at a time "<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --comms-sequential : Synchronous MPI calls; one dirs at a time "<<std::endl;
|
2017-08-20 01:10:50 +01:00
|
|
|
std::cout<<GridLogMessage<<" --comms-overlap : Overlap comms with compute "<<std::endl;
|
2017-02-10 23:22:31 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<" --dslash-generic: Wilson kernel for generic Nc"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --dslash-unroll : Wilson kernel for Nc=3"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --dslash-asm : Wilson kernel for AVX512"<<std::endl;
|
2017-02-10 23:22:31 +00:00
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<" --lebesgue : Cache oblivious Lebesgue curve/Morton order/Z-graph stencil looping"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<" --cacheblocking n.m.o.p : Hypercuboidal cache blocking"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<std::endl;
|
|
|
|
exit(EXIT_SUCCESS);
|
2015-05-19 14:54:42 +01:00
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
////////////////////////////////////
|
|
|
|
// Debug and performance options
|
|
|
|
////////////////////////////////////
|
|
|
|
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--dslash-unroll") ){
|
2018-01-15 09:37:58 +00:00
|
|
|
WilsonKernelsStatic::Opt=WilsonKernelsStatic::OptHandUnroll;
|
|
|
|
StaggeredKernelsStatic::Opt=StaggeredKernelsStatic::OptHandUnroll;
|
2016-11-02 08:07:09 +00:00
|
|
|
}
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--dslash-asm") ){
|
2018-01-15 09:37:58 +00:00
|
|
|
WilsonKernelsStatic::Opt=WilsonKernelsStatic::OptInlineAsm;
|
|
|
|
StaggeredKernelsStatic::Opt=StaggeredKernelsStatic::OptInlineAsm;
|
2016-11-02 08:07:09 +00:00
|
|
|
}
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--dslash-generic") ){
|
2018-01-15 09:37:58 +00:00
|
|
|
WilsonKernelsStatic::Opt=WilsonKernelsStatic::OptGeneric;
|
|
|
|
StaggeredKernelsStatic::Opt=StaggeredKernelsStatic::OptGeneric;
|
2016-11-02 08:07:09 +00:00
|
|
|
}
|
2017-02-10 23:22:31 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--comms-overlap") ){
|
2018-01-15 09:37:58 +00:00
|
|
|
WilsonKernelsStatic::Comms = WilsonKernelsStatic::CommsAndCompute;
|
2017-02-10 23:22:31 +00:00
|
|
|
} else {
|
2018-01-15 09:37:58 +00:00
|
|
|
WilsonKernelsStatic::Comms = WilsonKernelsStatic::CommsThenCompute;
|
2017-02-10 23:22:31 +00:00
|
|
|
}
|
2017-02-21 10:24:27 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--comms-concurrent") ){
|
|
|
|
CartesianCommunicator::SetCommunicatorPolicy(CartesianCommunicator::CommunicatorPolicyConcurrent);
|
2017-02-10 23:22:31 +00:00
|
|
|
}
|
2017-02-21 10:24:27 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--comms-sequential") ){
|
|
|
|
CartesianCommunicator::SetCommunicatorPolicy(CartesianCommunicator::CommunicatorPolicySequential);
|
2016-11-02 08:07:09 +00:00
|
|
|
}
|
2017-08-20 01:10:50 +01:00
|
|
|
|
2016-11-02 08:07:09 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--lebesgue") ){
|
|
|
|
LebesgueOrder::UseLebesgueOrder=1;
|
|
|
|
}
|
2017-07-29 18:06:53 +01:00
|
|
|
CartesianCommunicator::nCommThreads = -1;
|
2017-08-20 01:10:50 +01:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--comms-threads") ){
|
|
|
|
arg= GridCmdOptionPayload(*argv,*argv+*argc,"--comms-threads");
|
2017-07-29 18:06:53 +01:00
|
|
|
GridCmdOptionInt(arg,CartesianCommunicator::nCommThreads);
|
|
|
|
}
|
2016-11-02 08:07:09 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--cacheblocking") ){
|
|
|
|
arg= GridCmdOptionPayload(*argv,*argv+*argc,"--cacheblocking");
|
|
|
|
GridCmdOptionIntVector(arg,LebesgueOrder::Block);
|
|
|
|
}
|
2016-11-03 11:40:26 +00:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--notimestamp") ){
|
|
|
|
GridLogTimestamp(0);
|
2017-03-21 07:11:35 +00:00
|
|
|
} else {
|
2016-11-02 08:07:09 +00:00
|
|
|
GridLogTimestamp(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
GridParseLayout(*argv,*argc,
|
|
|
|
Grid_default_latt,
|
|
|
|
Grid_default_mpi);
|
|
|
|
|
2018-01-08 11:28:52 +00:00
|
|
|
std::cout << GridLogMessage << "Requesting "<< GlobalSharedMemory::MAX_MPI_SHM_BYTES <<" byte stencil comms buffers "<<std::endl;
|
|
|
|
if ( GlobalSharedMemory::Hugepages) {
|
2017-08-20 01:10:50 +01:00
|
|
|
std::cout << GridLogMessage << "Mapped stencil comms buffers as MAP_HUGETLB "<<std::endl;
|
|
|
|
}
|
2016-11-02 08:07:09 +00:00
|
|
|
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--decomposition") ){
|
2017-08-06 10:46:19 +01:00
|
|
|
std::cout<<GridLogMessage<<"Grid Default Decomposition patterns\n";
|
2016-11-02 08:07:09 +00:00
|
|
|
std::cout<<GridLogMessage<<"\tOpenMP threads : "<<GridThread::GetThreads()<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"\tMPI tasks : "<<GridCmdVectorIntToString(GridDefaultMpi())<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"\tvRealF : "<<sizeof(vRealF)*8 <<"bits ; " <<GridCmdVectorIntToString(GridDefaultSimd(4,vRealF::Nsimd()))<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"\tvRealD : "<<sizeof(vRealD)*8 <<"bits ; " <<GridCmdVectorIntToString(GridDefaultSimd(4,vRealD::Nsimd()))<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"\tvComplexF : "<<sizeof(vComplexF)*8 <<"bits ; " <<GridCmdVectorIntToString(GridDefaultSimd(4,vComplexF::Nsimd()))<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"\tvComplexD : "<<sizeof(vComplexD)*8 <<"bits ; " <<GridCmdVectorIntToString(GridDefaultSimd(4,vComplexD::Nsimd()))<<std::endl;
|
|
|
|
}
|
2016-10-24 17:30:43 +01:00
|
|
|
Grid_is_initialised = 1;
|
2015-07-23 17:31:13 +01:00
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2017-03-21 07:11:35 +00:00
|
|
|
|
2015-04-10 04:22:36 +01:00
|
|
|
void Grid_finalize(void)
|
|
|
|
{
|
2017-06-24 23:10:24 +01:00
|
|
|
#if defined (GRID_COMMS_MPI) || defined (GRID_COMMS_MPI3) || defined (GRID_COMMS_MPIT)
|
2015-04-10 04:22:36 +01:00
|
|
|
MPI_Finalize();
|
2015-05-11 12:43:10 +01:00
|
|
|
Grid_unquiesce_nodes();
|
2015-04-10 04:22:36 +01:00
|
|
|
#endif
|
2017-02-28 21:31:54 +00:00
|
|
|
#if defined (GRID_COMMS_SHMEM)
|
|
|
|
shmem_finalize();
|
|
|
|
#endif
|
2018-01-24 13:09:53 +00:00
|
|
|
Grid_is_initialised = 0;
|
2015-04-10 04:22:36 +01:00
|
|
|
}
|
2015-03-04 13:43:19 +00:00
|
|
|
|
2017-03-21 07:11:35 +00:00
|
|
|
void GridLogLayout() {
|
2018-01-12 23:29:22 +00:00
|
|
|
std::cout << GridLogMessage << "Grid Layout\n";
|
|
|
|
std::cout << GridLogMessage << "\tGlobal lattice size : "<< GridCmdVectorIntToString(GridDefaultLatt()) << std::endl;
|
|
|
|
std::cout << GridLogMessage << "\tOpenMP threads : "<< GridThread::GetThreads() <<std::endl;
|
|
|
|
std::cout << GridLogMessage << "\tMPI tasks : "<< GridCmdVectorIntToString(GridDefaultMpi()) << std::endl;
|
2017-03-21 07:11:35 +00:00
|
|
|
}
|
|
|
|
|
2015-04-23 20:42:30 +01:00
|
|
|
void * Grid_backtrace_buffer[_NBACKTRACE];
|
|
|
|
|
2015-03-04 13:43:19 +00:00
|
|
|
void Grid_sa_signal_handler(int sig,siginfo_t *si,void * ptr)
|
|
|
|
{
|
2017-02-07 05:57:55 +00:00
|
|
|
fprintf(stderr,"Caught signal %d\n",si->si_signo);
|
|
|
|
fprintf(stderr," mem address %llx\n",(unsigned long long)si->si_addr);
|
|
|
|
fprintf(stderr," code %d\n",si->si_code);
|
2015-11-06 10:31:24 +00:00
|
|
|
// Linux/Posix
|
2016-02-23 15:57:38 +00:00
|
|
|
#ifdef __linux__
|
2015-11-06 10:31:24 +00:00
|
|
|
// And x86 64bit
|
2016-02-23 15:57:38 +00:00
|
|
|
#ifdef __x86_64__
|
|
|
|
ucontext_t * uc= (ucontext_t *)ptr;
|
2015-03-04 13:43:19 +00:00
|
|
|
struct sigcontext *sc = (struct sigcontext *)&uc->uc_mcontext;
|
2017-02-07 05:57:55 +00:00
|
|
|
fprintf(stderr," instruction %llx\n",(unsigned long long)sc->rip);
|
2015-05-11 18:59:03 +01:00
|
|
|
#define REG(A) printf(" %s %lx\n",#A,sc-> A);
|
2015-03-04 13:43:19 +00:00
|
|
|
REG(rdi);
|
|
|
|
REG(rsi);
|
|
|
|
REG(rbp);
|
|
|
|
REG(rbx);
|
|
|
|
REG(rdx);
|
|
|
|
REG(rax);
|
|
|
|
REG(rcx);
|
|
|
|
REG(rsp);
|
|
|
|
REG(rip);
|
|
|
|
|
|
|
|
|
|
|
|
REG(r8);
|
|
|
|
REG(r9);
|
|
|
|
REG(r10);
|
|
|
|
REG(r11);
|
|
|
|
REG(r12);
|
|
|
|
REG(r13);
|
|
|
|
REG(r14);
|
|
|
|
REG(r15);
|
|
|
|
#endif
|
2015-04-23 20:42:30 +01:00
|
|
|
#endif
|
2017-02-07 05:57:55 +00:00
|
|
|
fflush(stderr);
|
|
|
|
BACKTRACEFP(stderr);
|
|
|
|
fprintf(stderr,"Called backtrace\n");
|
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2015-04-23 20:42:30 +01:00
|
|
|
exit(0);
|
2015-03-04 13:43:19 +00:00
|
|
|
return;
|
|
|
|
};
|
2016-09-26 09:36:14 +01:00
|
|
|
|
2015-03-04 13:43:19 +00:00
|
|
|
void Grid_debug_handler_init(void)
|
|
|
|
{
|
2018-01-24 13:09:53 +00:00
|
|
|
struct sigaction sa;
|
2015-03-04 13:43:19 +00:00
|
|
|
sigemptyset (&sa.sa_mask);
|
|
|
|
sa.sa_sigaction= Grid_sa_signal_handler;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
sigaction(SIGSEGV,&sa,NULL);
|
|
|
|
sigaction(SIGTRAP,&sa,NULL);
|
2017-02-07 05:57:55 +00:00
|
|
|
sigaction(SIGBUS,&sa,NULL);
|
2016-09-26 09:36:14 +01:00
|
|
|
|
2016-03-30 08:42:34 +01:00
|
|
|
feenableexcept( FE_INVALID|FE_OVERFLOW|FE_DIVBYZERO);
|
2016-09-26 09:36:14 +01:00
|
|
|
|
2016-03-30 08:42:34 +01:00
|
|
|
sigaction(SIGFPE,&sa,NULL);
|
2017-02-07 05:57:55 +00:00
|
|
|
sigaction(SIGKILL,&sa,NULL);
|
2017-04-13 10:51:40 +01:00
|
|
|
sigaction(SIGILL,&sa,NULL);
|
2015-03-04 13:43:19 +00:00
|
|
|
}
|
2018-01-12 23:29:22 +00:00
|
|
|
|
|
|
|
NAMESPACE_END(Grid);
|