GADGET-4
shared_mem_handler.h
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#ifndef SHAREDMEM_H
13#define SHAREDMEM_H
14
15#include <hdf5.h>
16#include <mpi.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <algorithm>
20#include <atomic>
21#include <cstring>
22
23#include "../data/simparticles.h"
24
25#define MAX_TREE_INFOS 10
26
27class shmem
28{
29 public:
30 MPI_Comm SharedMemComm; // the communicator linking the processes that have mutual shared memory access in the same node
31 MPI_Comm SimulationComm; // the communicator containing all the compute processors (or all the ghost processors)
32
33 int World_ThisTask; // rank
34 int World_NTask; // total number of MPI processes
35
36 int Island_ThisTask; // rank in current shared memory region
37 int Island_NTask; // number of MPI tasks in shared memory region
38
39 int Sim_ThisTask; // rank in simulation partition
40 int Sim_NTask; // size of MPI tasks in simulation partition
41
42 int GhostRank; // equal to 1 if we are a ghost rank, otherwise zero
43
44 int Island_Smallest_WorldTask; // this is the smallest global rank in the shared memory node
45
46 // we need a table that maps the rank of a destination processor in the
47 // simulation communicator to the rank of the responsible ghost processor in
48 // the global communicator
50
51 // we need a table that maps the rank of a destination processor in the
52 // simulation communicator to the rank in the shared memory communicator
54
55 // we need a table that maps the rank of a simulation processor to the
56 // smallest world rank in its shared memory node. With this we can decide
57 // whether two ranks are on the same node
59
60 // the rank in the global communicator that a processor should turn to for a shared memory request
62
63 MPI_Win SharedMemWin;
64
66
67#ifdef ALLOCATE_SHARED_MEMORY_VIA_POSIX
68 char **SharedMemBaseAddrRaw;
69#endif
70
71 char *TableData;
72 char *EwaldData;
73
75 {
82 };
83
85 {
87
88 ptrdiff_t *TopNodes_offsets;
89 ptrdiff_t *Nodes_offsets;
90 ptrdiff_t *Nextnode_offsets;
91 ptrdiff_t *Points_offsets;
92 ptrdiff_t *P_offsets;
93 ptrdiff_t *SphP_offsets;
96
101 };
102
105
106 inline char *get_basenodep(int no, unsigned char shmrank, int handle)
107 {
108 if(no < tree_info[handle].Bd.MaxPart + tree_info[handle].Bd.NTopnodes)
109 return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].TopNodes_offsets[shmrank]);
110 else
111 return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].Nodes_offsets[shmrank]);
112 }
113
114 inline int *get_nextnodep(unsigned char shmrank, int handle)
115 {
116 return (int *)((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].Nextnode_offsets[shmrank]);
117 }
118
119 inline char *get_pointsp(unsigned char shmrank, int handle)
120 {
121 return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].Points_offsets[shmrank]);
122 }
123
124 inline char *get_Pp(unsigned char shmrank, int handle)
125 {
126 return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].P_offsets[shmrank]);
127 }
128
129 inline char *get_SphPp(unsigned char shmrank, int handle)
130 {
131 return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].SphP_offsets[shmrank]);
132 }
133
134 void deal_with_gravity_node_request(char *message, int length, int source, int handle);
135 void deal_with_sph_node_request(char *message, int length, int source, int handle, simparticles *Sp);
136
137 void prepare_offset_table(void *p, ptrdiff_t *&offset_tab);
138 void inform_offset_table(void *p);
139 void free_offset_table(ptrdiff_t *&offset_tab);
140
141 void shared_memory_handler(void);
142};
143
144extern shmem Shmem;
145
146#endif
void prepare_offset_table(void *p, ptrdiff_t *&offset_tab)
void deal_with_gravity_node_request(char *message, int length, int source, int handle)
MPI_Comm SharedMemComm
char * TableData
int * get_nextnodep(unsigned char shmrank, int handle)
void deal_with_sph_node_request(char *message, int length, int source, int handle, simparticles *Sp)
void shared_memory_handler(void)
int * GetNodeIDForSimulCommRank
int Island_ThisTask
void inform_offset_table(void *p)
int Island_NTask
void ** SharedMemBaseAddr
int * GetShmRankForSimulCommRank
MPI_Comm SimulationComm
tree_storage_info tree_info[MAX_TREE_INFOS]
int Island_Smallest_WorldTask
int Sim_ThisTask
int * GetGhostRankForSimulCommRank
char * get_basenodep(int no, unsigned char shmrank, int handle)
char * EwaldData
int MyShmRankInGlobal
char * get_pointsp(unsigned char shmrank, int handle)
char * get_Pp(unsigned char shmrank, int handle)
MPI_Win SharedMemWin
char * get_SphPp(unsigned char shmrank, int handle)
int World_ThisTask
void free_offset_table(ptrdiff_t *&offset_tab)
#define MAX_TREE_INFOS
shmem Shmem
Definition: main.cc:45