12 #ifndef SST_CORE_INTERPROCESS_TUNNEL_MMAP_PARENT_H 13 #define SST_CORE_INTERPROCESS_TUNNEL_MMAP_PARENT_H 41 int SST_MPI_Comm_spawn_multiple(
int count,
char* array_of_commands[],
char** array_of_argv[],
42 const int array_of_maxprocs[],
const char* array_of_env[]);
49 template <
typename TunnelType>
63 MMAPParent(uint32_t comp_id,
size_t numBuffers,
size_t bufferSize, uint32_t expectedChildren = 1) :
68 memset(key,
'\0',
sizeof(key));
70 snprintf(key,
sizeof(key),
"/tmp/sst_shmem_%u-%" PRIu32
"-%d", getpid(), comp_id, rand());
73 fd = open(filename.c_str(), O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
81 }
while ( (fd < 0) && (errno == EEXIST) );
85 fprintf(stderr,
"Failed to create IPC region '%s': %s\n", filename.c_str(), strerror(errno));
89 tunnel =
new TunnelType(numBuffers, bufferSize, expectedChildren);
90 shmSize = tunnel->getTunnelSize();
92 if ( ftruncate(fd, shmSize) ) {
94 fprintf(stderr,
"Resizing shared file '%s' failed: %s\n", filename.c_str(), strerror(errno));
98 shmPtr = mmap(
nullptr, shmSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
99 if ( shmPtr == MAP_FAILED ) {
101 fprintf(stderr,
"mmap failed: %s\n", strerror(errno));
106 memset(shmPtr,
'\0', shmSize);
107 tunnel->initialize(shmPtr);
115 munmap(shmPtr, shmSize);
116 if (
remove(filename.c_str()) != 0 ) {
117 fprintf(stderr,
"Error deleting tunnel file: %s\n", filename.c_str());
131 std::string filename;
139 #endif // SST_CORE_INTERPROCESS_TUNNEL_MMAP_PARENT_H virtual ~MMAPParent()
Destructor.
Definition: mmapparent.h:111
Definition: circularBuffer.h:20
const std::string & getRegionName() const
returns name of the mmap'd file
Definition: mmapparent.h:122
MMAPParent(uint32_t comp_id, size_t numBuffers, size_t bufferSize, uint32_t expectedChildren=1)
Parent/master manager for an IPC Tunnel Creates a memory-mapped file and initializes a TunnelType dat...
Definition: mmapparent.h:63
TunnelType * getTunnel()
return the created tunnel pointer
Definition: mmapparent.h:125
Class supports an IPC tunnel between two or more processes, via an mmap'd file.
Definition: mmapparent.h:50