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>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#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-04-18 22:17:01 +01:00
|
|
|
#include <Grid.h>
|
2015-05-11 12:43:10 +01:00
|
|
|
#include <algorithm>
|
2015-05-20 09:32:46 +01:00
|
|
|
#include <iterator>
|
2015-03-04 13:43:19 +00:00
|
|
|
|
2015-11-04 11:16:56 +00:00
|
|
|
#define __X86_64
|
|
|
|
#define EXECINFO
|
|
|
|
#ifdef EXECINFO
|
2015-04-23 20:42:30 +01:00
|
|
|
#include <execinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2015-04-03 05:29:54 +01:00
|
|
|
namespace Grid {
|
2015-03-04 13:43:19 +00:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// Convenience functions to access stadard command line arg
|
|
|
|
// driven parallelism controls
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
static std::vector<int> Grid_default_latt;
|
|
|
|
static std::vector<int> Grid_default_mpi;
|
|
|
|
int GridThread::_threads;
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<int> &GridDefaultLatt(void) {return Grid_default_latt;};
|
|
|
|
const std::vector<int> &GridDefaultMpi(void) {return Grid_default_mpi;};
|
|
|
|
const std::vector<int> GridDefaultSimd(int dims,int nsimd)
|
|
|
|
{
|
2015-05-12 20:41:44 +01:00
|
|
|
std::vector<int> layout(dims);
|
|
|
|
int nn=nsimd;
|
|
|
|
for(int d=dims-1;d>=0;d--){
|
|
|
|
if ( nn>=2) {
|
|
|
|
layout[d]=2;
|
|
|
|
nn/=2;
|
|
|
|
} else {
|
|
|
|
layout[d]=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(nn==1);
|
|
|
|
return layout;
|
2015-07-23 17:31:13 +01:00
|
|
|
}
|
2015-05-12 20:41:44 +01: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;
|
|
|
|
}
|
2015-07-23 17:31:13 +01:00
|
|
|
// Comma separated list
|
|
|
|
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
|
|
|
|
|
|
|
void GridCmdOptionIntVector(std::string &str,std::vector<int> & vec)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
return;
|
2015-03-04 13:43:19 +00:00
|
|
|
}
|
2015-05-11 12:43:10 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
|
2015-05-11 14:36:48 +01:00
|
|
|
void GridParseLayout(char **argv,int argc,
|
|
|
|
std::vector<int> &latt,
|
|
|
|
std::vector<int> &mpi)
|
2015-05-11 12:43:10 +01:00
|
|
|
{
|
|
|
|
mpi =std::vector<int>({1,1,1,1});
|
2015-05-11 14:36:48 +01:00
|
|
|
latt=std::vector<int>({8,8,8,8});
|
|
|
|
|
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-05-11 18:59:03 +01:00
|
|
|
if( GridCmdOptionExists(argv,argv+argc,"--omp") ){
|
|
|
|
std::vector<int> ompthreads(0);
|
|
|
|
arg= GridCmdOptionPayload(argv,argv+argc,"--omp");
|
|
|
|
GridCmdOptionIntVector(arg,ompthreads);
|
|
|
|
assert(ompthreads.size()==1);
|
|
|
|
GridThread::SetThreads(ompthreads[0]);
|
|
|
|
}
|
|
|
|
|
2015-05-11 12:43:10 +01:00
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2015-05-19 14:54:42 +01:00
|
|
|
std::string GridCmdVectorIntToString(const std::vector<int> & vec){
|
|
|
|
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
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////
|
2015-05-11 18:59:03 +01:00
|
|
|
void Grid_init(int *argc,char ***argv)
|
|
|
|
{
|
|
|
|
#ifdef GRID_COMMS_MPI
|
|
|
|
MPI_Init(argc,argv);
|
|
|
|
#endif
|
|
|
|
// Parse command line args.
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
GridLogger::StopWatch.Start();
|
|
|
|
|
|
|
|
std::string arg;
|
|
|
|
std::vector<std::string> logstreams;
|
|
|
|
std::string defaultLog("Error,Warning,Message,Performance");
|
|
|
|
|
|
|
|
GridCmdOptionCSL(defaultLog,logstreams);
|
|
|
|
GridLogConfigure(logstreams);
|
|
|
|
|
2015-05-19 14:54:42 +01:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--help") ){
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<<"--help : this message"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--debug-signals : catch sigsegv and print a blame report"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--debug-stdout : print stdout from EVERY node"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--decomposition : report on default omp,mpi and simd decomposition"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--mpi n.n.n.n : default MPI decomposition"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--omp n : default number of OMP threads"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--grid n.n.n.n : default Grid size"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage<<"--log list : comma separted list of streams from Error,Warning,Message,Performance,Iterative,Debug"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2015-05-11 18:59:03 +01:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--debug-signals") ){
|
|
|
|
Grid_debug_handler_init();
|
|
|
|
}
|
|
|
|
if( !GridCmdOptionExists(*argv,*argv+*argc,"--debug-stdout") ){
|
|
|
|
Grid_quiesce_nodes();
|
|
|
|
}
|
2015-05-26 19:54:03 +01:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--dslash-opt") ){
|
Binary IO file for generic Grid array parallel I/O.
Number of IO MPI tasks can be varied by selecting which
dimensions use parallel IO and which dimensions use Serial send to boss
I/O.
Thus can neck down from, say 1024 nodes = 4x4x8x8 to {1,8,32,64,128,256,1024} nodes
doing the I/O.
Interpolates nicely between ALL nodes write their data, a single boss per time-plane
in processor space [old UKQCD fortran code did this], and a single node doing all I/O.
Not sure I have the transfer sizes big enough and am not overly convinced fstream
is guaranteed to not give buffer inconsistencies unless I set streambuf size to zero.
Practically it has worked on 8 tasks, 2x1x2x2 writing /cloning NERSC configurations
on my MacOS + OpenMPI and Clang environment.
It is VERY easy to switch to pwrite at a later date, and also easy to send x-strips around from
each node in order to gather bigger chunks at the syscall level.
That would push us up to the circa 8x 18*4*8 == 4KB size write chunk, and by taking, say, x/y non
parallel we get to 16MB contiguous chunks written in multi 4KB transactions
per IOnode in 64^3 lattices for configuration I/O.
I suspect this is fine for system performance.
2015-08-26 13:40:29 +01:00
|
|
|
QCD::WilsonFermionStatic::HandOptDslash=1;
|
2015-09-25 16:55:04 +01:00
|
|
|
QCD::WilsonFermion5DStatic::HandOptDslash=1;
|
2015-05-31 15:09:02 +01:00
|
|
|
}
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--lebesgue") ){
|
|
|
|
LebesgueOrder::UseLebesgueOrder=1;
|
2015-05-26 19:54:03 +01:00
|
|
|
}
|
2015-11-04 11:16:56 +00:00
|
|
|
|
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--cacheblocking") ){
|
|
|
|
arg= GridCmdOptionPayload(*argv,*argv+*argc,"--cacheblocking");
|
|
|
|
GridCmdOptionIntVector(arg,LebesgueOrder::Block);
|
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
GridParseLayout(*argv,*argc,
|
|
|
|
Grid_default_latt,
|
|
|
|
Grid_default_mpi);
|
2015-05-19 14:54:42 +01:00
|
|
|
if( GridCmdOptionExists(*argv,*argv+*argc,"--decomposition") ){
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage<<"Grid Decomposition\n";
|
|
|
|
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;
|
2015-05-19 14:54:42 +01:00
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
}
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2015-05-11 14:36:48 +01:00
|
|
|
|
2015-04-10 04:22:36 +01:00
|
|
|
void Grid_finalize(void)
|
|
|
|
{
|
|
|
|
#ifdef GRID_COMMS_MPI
|
|
|
|
MPI_Finalize();
|
2015-05-11 12:43:10 +01:00
|
|
|
Grid_unquiesce_nodes();
|
2015-04-10 04:22:36 +01:00
|
|
|
#endif
|
|
|
|
}
|
2015-03-04 13:43:19 +00:00
|
|
|
double usecond(void) {
|
|
|
|
struct timeval tv;
|
|
|
|
gettimeofday(&tv,NULL);
|
|
|
|
return 1.0*tv.tv_usec + 1.0e6*tv.tv_sec;
|
|
|
|
}
|
|
|
|
|
2015-04-23 20:42:30 +01:00
|
|
|
#define _NBACKTRACE (256)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
printf("Caught signal %d\n",si->si_signo);
|
2015-05-11 18:59:03 +01:00
|
|
|
printf(" mem address %llx\n",(unsigned long long)si->si_addr);
|
2015-03-04 13:43:19 +00:00
|
|
|
printf(" code %d\n",si->si_code);
|
|
|
|
|
|
|
|
#ifdef __X86_64
|
2015-03-29 20:35:37 +01:00
|
|
|
ucontext_t * uc= (ucontext_t *)ptr;
|
2015-03-04 13:43:19 +00:00
|
|
|
struct sigcontext *sc = (struct sigcontext *)&uc->uc_mcontext;
|
2015-05-11 18:59:03 +01:00
|
|
|
printf(" instruction %llx\n",(unsigned long long)sc->rip);
|
|
|
|
#define REG(A) printf(" %s %lx\n",#A,sc-> A);
|
2015-11-04 11:16:56 +00:00
|
|
|
|
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-11-04 11:16:56 +00:00
|
|
|
#ifdef EXECINFO
|
2015-04-23 20:42:30 +01:00
|
|
|
int symbols = backtrace (Grid_backtrace_buffer,_NBACKTRACE);
|
|
|
|
char **strings = backtrace_symbols(Grid_backtrace_buffer,symbols);
|
|
|
|
for (int i = 0; i < symbols; i++){
|
|
|
|
printf ("%s\n", strings[i]);
|
2015-03-04 13:43:19 +00:00
|
|
|
}
|
2015-04-23 20:42:30 +01:00
|
|
|
#endif
|
|
|
|
exit(0);
|
2015-03-04 13:43:19 +00:00
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
void Grid_debug_handler_init(void)
|
|
|
|
{
|
|
|
|
struct sigaction sa,osa;
|
|
|
|
sigemptyset (&sa.sa_mask);
|
|
|
|
sa.sa_sigaction= Grid_sa_signal_handler;
|
|
|
|
sa.sa_flags = SA_SIGINFO;
|
|
|
|
sigaction(SIGSEGV,&sa,NULL);
|
|
|
|
sigaction(SIGTRAP,&sa,NULL);
|
|
|
|
}
|
|
|
|
}
|