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 
27 class 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  char *TableData;
68  char *EwaldData;
69 
71  {
72  int MaxPart;
73  int MaxNodes;
74  int NTopnodes;
78  };
79 
81  {
83 
84  ptrdiff_t *TopNodes_offsets;
85  ptrdiff_t *Nodes_offsets;
86  ptrdiff_t *Nextnode_offsets;
87  ptrdiff_t *Points_offsets;
88  ptrdiff_t *P_offsets;
89  ptrdiff_t *SphP_offsets;
92 
97  };
98 
100  int num_tree_info = 0;
101 
102  inline char *get_basenodep(int no, unsigned char shmrank, int handle)
103  {
104  if(no < tree_info[handle].Bd.MaxPart + tree_info[handle].Bd.NTopnodes)
105  return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].TopNodes_offsets[shmrank]);
106  else
107  return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].Nodes_offsets[shmrank]);
108  }
109 
110  inline int *get_nextnodep(unsigned char shmrank, int handle)
111  {
112  return (int *)((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].Nextnode_offsets[shmrank]);
113  }
114 
115  inline char *get_pointsp(unsigned char shmrank, int handle)
116  {
117  return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].Points_offsets[shmrank]);
118  }
119 
120  inline char *get_Pp(unsigned char shmrank, int handle)
121  {
122  return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].P_offsets[shmrank]);
123  }
124 
125  inline char *get_SphPp(unsigned char shmrank, int handle)
126  {
127  return ((char *)SharedMemBaseAddr[shmrank] + tree_info[handle].SphP_offsets[shmrank]);
128  }
129 
130  void deal_with_gravity_node_request(char *message, int length, int source, int handle);
131  void deal_with_sph_node_request(char *message, int length, int source, int handle, simparticles *Sp);
132 
133  void prepare_offset_table(void *p, ptrdiff_t *&offset_tab);
134  void inform_offset_table(void *p);
135  void free_offset_table(ptrdiff_t *&offset_tab);
136 
137  void shared_memory_handler(void);
138 };
139 
140 extern shmem Shmem;
141 
142 #endif
char * get_basenodep(int no, unsigned char shmrank, int handle)
char * get_SphPp(unsigned char shmrank, int handle)
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
int * get_nextnodep(unsigned char shmrank, int handle)
char * TableData
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
char * get_pointsp(unsigned char shmrank, int handle)
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
char * get_Pp(unsigned char shmrank, int handle)
int Sim_ThisTask
int * GetGhostRankForSimulCommRank
char * EwaldData
int MyShmRankInGlobal
MPI_Win SharedMemWin
int World_ThisTask
void free_offset_table(ptrdiff_t *&offset_tab)
#define MAX_TREE_INFOS
shmem Shmem
Definition: main.cc:45