43#ifndef ACCELERATOR_AWARE_MPI
44void * GlobalSharedMemory::HostCommBuf;
72#ifndef ACCELERATOR_AWARE_MPI
73void *SharedMemory::HostBufferMalloc(
size_t bytes){
74 void *ptr = (
void *)host_heap_top;
75 host_heap_top += bytes;
76 host_heap_bytes+= bytes;
77 if (host_heap_bytes >= host_heap_size) {
78 std::cout<<
" HostBufferMalloc exceeded heap size -- try increasing with --shm <MB> flag" <<std::endl;
79 std::cout<<
" Parameter specified in units of MB (megabytes) " <<std::endl;
80 std::cout<<
" Current alloc is " << (bytes/(1024*1024)) <<
"MB"<<std::endl;
81 std::cout<<
" Current bytes is " << (host_heap_bytes/(1024*1024)) <<
"MB"<<std::endl;
82 std::cout<<
" Current heap is " << (host_heap_size/(1024*1024)) <<
"MB"<<std::endl;
83 assert(host_heap_bytes<host_heap_size);
87void SharedMemory::HostBufferFreeAll(
void) {
88 host_heap_top =(size_t)HostCommBuf;
98 std::cout<<
" ShmBufferMalloc exceeded shared heap size -- try increasing with --shm <MB> flag" <<std::endl;
99 std::cout<<
" Parameter specified in units of MB (megabytes) " <<std::endl;
100 std::cout<<
" Current alloc is " << (bytes/(1024*1024)) <<
"MB"<<std::endl;
101 std::cout<<
" Current bytes is " << (
heap_bytes/(1024*1024)) <<
"MB"<<std::endl;
102 std::cout<<
" Current heap is " << (
heap_size/(1024*1024)) <<
"MB"<<std::endl;
119 return ( b == ( (b/a)*a ) );
126 char* str = getenv((
"GRID_SHM_DIMS_" + std::to_string(ShmDims.
size())).c_str());
128 std::vector<int> IntShmDims;
130 assert(IntShmDims.size() == WorldDims.
size());
132 for (
int dim=0;dim<WorldDims.
size();dim++) {
133 ShmSize *= (ShmDims[dim] = IntShmDims[dim]);
134 assert(
divides(ShmDims[dim],WorldDims[dim]));
143 int ndimension = WorldDims.
size();
146 std::vector<int> primes({2,3,5});
149 int last_dim = ndimension - 1;
153 for(p=0;p<primes.size();p++) {
155 if (
divides(prime,WorldDims[dim]/ShmDims[dim])
163 if (p == primes.size() && last_dim == dim) {
164 std::cerr <<
"GlobalSharedMemory::GetShmDims failed" << std::endl;
167 dim=(dim+1) %ndimension;
AcceleratorVector< int, MaxDims > Coordinate
void GridCmdOptionIntVector(const std::string &str, VectorInt &vec)
#define NAMESPACE_BEGIN(A)
static int divides(int a, int b)
accelerator_inline size_type size(void) const
static void SharedMemoryFree(void)
static Grid_MPI_Comm WorldComm
static uint64_t _ShmAllocBytes
static std::vector< int > WorldShmRanks
static void GetShmDims(const Coordinate &WorldDims, Coordinate &ShmDims)
static uint64_t MAX_MPI_SHM_BYTES
static std::vector< void * > WorldShmCommBufs
static Grid_MPI_Comm WorldShmComm
void * ShmBufferSelf(void)
void * ShmBufferMalloc(size_t bytes)
void ShmBufferFreeAll(void)
std::vector< void * > ShmCommBufs