1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

MAP_HUGETLB portability fix

This commit is contained in:
paboyle 2017-08-20 03:08:54 +01:00
parent ae56e556c6
commit b49bec0cec
2 changed files with 9 additions and 8 deletions

View File

@ -149,7 +149,9 @@ void CartesianCommunicator::ShmInitGeneric(void){
#if 1 #if 1
int mmap_flag = MAP_SHARED | MAP_ANONYMOUS; int mmap_flag = MAP_SHARED | MAP_ANONYMOUS;
#ifdef MAP_HUGETLB
if ( Hugepages ) mmap_flag |= MAP_HUGETLB; if ( Hugepages ) mmap_flag |= MAP_HUGETLB;
#endif
ShmCommBuf =(void *) mmap(NULL, MAX_MPI_SHM_BYTES, PROT_READ | PROT_WRITE, mmap_flag, -1, 0); ShmCommBuf =(void *) mmap(NULL, MAX_MPI_SHM_BYTES, PROT_READ | PROT_WRITE, mmap_flag, -1, 0);
if (ShmCommBuf == (void *)MAP_FAILED) exit(EXIT_FAILURE); if (ShmCommBuf == (void *)MAP_FAILED) exit(EXIT_FAILURE);
std::cout << "ShmCommBuf "<<ShmCommBuf<<std::endl; std::cout << "ShmCommBuf "<<ShmCommBuf<<std::endl;

View File

@ -42,13 +42,6 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
#include <numaif.h> #include <numaif.h>
#endif #endif
// Make up for linex deficiencies
#ifndef SHM_HUGETLB
#define SHM_HUGETLB 0x0
#endif
#ifndef MAP_HUGETLB
#define MAP_HUGETLB 0x0
#endif
namespace Grid { namespace Grid {
@ -220,7 +213,9 @@ void CartesianCommunicator::Init(int *argc, char ***argv) {
ftruncate(fd, size); ftruncate(fd, size);
int mmap_flag = MAP_SHARED; int mmap_flag = MAP_SHARED;
#ifdef MAP_HUGETLB
if (Hugepages) mmap_flag |= MAP_HUGETLB; if (Hugepages) mmap_flag |= MAP_HUGETLB;
#endif
void * ptr = mmap(NULL,size, PROT_READ | PROT_WRITE, mmap_flag, fd, 0); void * ptr = mmap(NULL,size, PROT_READ | PROT_WRITE, mmap_flag, fd, 0);
if ( ptr == MAP_FAILED ) { perror("failed mmap"); assert(0); } if ( ptr == MAP_FAILED ) { perror("failed mmap"); assert(0); }
@ -274,7 +269,11 @@ void CartesianCommunicator::Init(int *argc, char ***argv) {
for(int r=0;r<ShmSize;r++){ for(int r=0;r<ShmSize;r++){
size_t size = CartesianCommunicator::MAX_MPI_SHM_BYTES; size_t size = CartesianCommunicator::MAX_MPI_SHM_BYTES;
key_t key = 0x4545 + r; key_t key = 0x4545 + r;
if ((shmids[r]= shmget(key,size, SHM_HUGETLB | IPC_CREAT | SHM_R | SHM_W)) < 0) { int flags = IPC_CREAT | SHM_R | SHM_W;
#ifdef SHM_HUGETLB
flags|=SHM_HUGETLB;
#endif
if ((shmids[r]= shmget(key,size, flags)) < 0) {
int errsv = errno; int errsv = errno;
printf("Errno %d\n",errsv); printf("Errno %d\n",errsv);
perror("shmget"); perror("shmget");