ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ghosts.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24/** \file
25 * Ghost particles and particle exchange.
26 *
27 * In this file you find everything concerning the exchange of
28 * particle data (particles, ghosts, positions and forces) for short
29 * range interactions between the spacial domains of neighbouring
30 * nodes.
31 *
32 * <h2> How does this work </h2>
33 * The ghost communication transfers data from cells on one node to cells on
34 * another node during the integration process. Note that data can only be
35 * transferred from one cell to one other, and the contents of the other cell
36 * will be overwritten.
37 *
38 * The particle data that has to be transferred, and especially from where to
39 * where, heavily depends on the cell system. In ESPResSo, this is abstracted
40 * in form of ghost communicators (\ref GhostCommunicator) and ghost
41 * communications (\ref GhostCommunication). The ghost communicators represent
42 * the four communications above and consist of the data to transfer (which is
43 * determined by their type) and a list of ghost communications. The data
44 * types are described by the particle data classes:
45 * - @ref GHOSTTRANS_PROPRTS transfers the @ref ParticleProperties
46 * - @ref GHOSTTRANS_POSITION transfers the @ref ParticlePosition
47 * - @ref GHOSTTRANS_MOMENTUM transfers the @ref ParticleMomentum
48 * - @ref GHOSTTRANS_FORCE transfers the @ref ParticleForce
49 * - @ref GHOSTTRANS_RATTLE transfers the @ref ParticleRattle
50 * - @ref GHOSTTRANS_PARTNUM transfers the cell sizes
51 *
52 * Each ghost communication describes a single communication of the local with
53 * another node (or all other nodes). The data transferred can be any number
54 * of cells, there are five communication types:
55 * - @ref GHOST_SEND sends data to one other node
56 * - @ref GHOST_RECV recvs data from one other node. In the case of
57 * forces, they are added up, everything else is overwritten
58 * - @ref GHOST_BCST sends data to all nodes
59 * - @ref GHOST_RDCE recvs data from all nodes. In the case of
60 * forces, they are added up, everything else is overwritten
61 * - @ref GHOST_LOCL transfer data from a local cell to another local cell.
62 * In this case, the first half of the cells are the sending cells, the
63 * other half are the corresponding receivers.
64 *
65 * Note that for the first four communications you have to make sure that
66 * when one node sends to another, that the sender has @ref GHOST_SEND
67 * and the receiver @ref GHOST_RECV. In the case of @ref GHOST_BCST resp.
68 * @ref GHOST_RDCE, all nodes have to have the same communication type
69 * and the same master sender/receiver (just like the MPI commands).
70 *
71 * A special topic are @ref GHOST_PREFETCH and @ref GHOST_PSTSTORE. For
72 * example, if all nodes broadcast to the other, the naive implementation will
73 * be that @c n_nodes times a @ref GHOST_BCST is done with different master
74 * nodes. But this means that each time <tt>n_nodes - 1</tt> nodes wait for
75 * the master to construct its send buffer. Therefore there is the prefetch
76 * flag which can be set on a pair of recv/send operations. If the ghost
77 * communication reaches a recv operation with prefetch, the next send
78 * operation (which must have the prefetch set!!) is searched and the send
79 * buffer already created. When sending, this precreated send buffer is used.
80 * In the scenario above, all nodes create the send buffers simultaneously in
81 * the first communication step, thereby reducing the latency a little bit.
82 * The pststore is similar and postpones the write back of received data
83 * until a send operation (with a precreated send buffer) is finished.
84 *
85 * The ghost communicators are created by the cell systems.
86 */
87
88#include <config/config.hpp>
89
90#include "BoxGeometry.hpp"
91#include "ParticleList.hpp"
92
93#include <utils/Vector.hpp>
94
95#include <boost/mpi/communicator.hpp>
96
97#include <cstddef>
98#include <utility>
99#include <vector>
100
101/** \name Transfer types, for \ref GhostCommunicator::type */
102/************************************************************/
103/**@{*/
104
105/// send to a single node
106#define GHOST_SEND 0
107/// recv from a single node
108#define GHOST_RECV 1
109/// broadcast, the node entry gives the sender
110#define GHOST_BCST 2
111/// reduce, the node entry gives the receiver
112#define GHOST_RDCE 3
113/// transfer data from cell to cell on this node
114#define GHOST_LOCL 4
115
116/// mask to the job area of the transfer type
117#define GHOST_JOBMASK 15
118/// additional flag for prefetching
119#define GHOST_PREFETCH 16
120/// additional flag for poststoring
121#define GHOST_PSTSTORE 32
122/**@}*/
123
124/** Transfer data classes, for \ref ghost_communicator */
125enum : unsigned {
127 /// transfer \ref ParticleProperties
129 /// transfer \ref ParticlePosition
131 /// transfer \ref ParticleMomentum
133 /// transfer \ref ParticleForce
135#ifdef ESPRESSO_BOND_CONSTRAINT
136 /// transfer \ref ParticleRattle
138#endif
139 /// resize the receiver particle arrays to the size of the senders
141 GHOSTTRANS_BONDS = 128u
143
145 /** Communication type. */
146 int type;
147 /** Node to communicate with (to use with all MPI operations). */
148 int node;
149
150 /** Pointer array to particle lists to communicate. */
151 std::vector<ParticleList *> part_lists = {};
152
153 /** Position shift for ghost particles. The shift is done on the sender side.
154 */
156};
157
158/** Properties for a ghost communication. */
160 GhostCommunicator() = default;
161 GhostCommunicator(boost::mpi::communicator comm, std::size_t size)
162 : mpi_comm(std::move(comm)), communications(size) {}
163
164 /** Attached mpi communicator */
165 boost::mpi::communicator mpi_comm;
166
167 /** List of ghost communications. */
168 std::vector<GhostCommunication> communications;
169};
170
171/**
172 * @brief Do a ghost communication with the specified data parts.
173 */
175 BoxGeometry const &box_geo, unsigned int data_parts);
Vector implementation and trait types for boost qvm interoperability.
@ GHOSTTRANS_MOMENTUM
transfer ParticleMomentum
Definition ghosts.hpp:132
@ GHOSTTRANS_RATTLE
transfer ParticleRattle
Definition ghosts.hpp:137
@ GHOSTTRANS_PARTNUM
resize the receiver particle arrays to the size of the senders
Definition ghosts.hpp:140
@ GHOSTTRANS_POSITION
transfer ParticlePosition
Definition ghosts.hpp:130
@ GHOSTTRANS_PROPRTS
transfer ParticleProperties
Definition ghosts.hpp:128
@ GHOSTTRANS_FORCE
transfer ParticleForce
Definition ghosts.hpp:134
@ GHOSTTRANS_NONE
Definition ghosts.hpp:126
@ GHOSTTRANS_BONDS
Definition ghosts.hpp:141
void ghost_communicator(GhostCommunicator const &gcr, BoxGeometry const &box_geo, unsigned int data_parts)
Do a ghost communication with the specified data parts.
Definition ghosts.cpp:442
STL namespace.
Utils::Vector3d shift
Position shift for ghost particles.
Definition ghosts.hpp:155
int node
Node to communicate with (to use with all MPI operations).
Definition ghosts.hpp:148
std::vector< ParticleList * > part_lists
Pointer array to particle lists to communicate.
Definition ghosts.hpp:151
int type
Communication type.
Definition ghosts.hpp:146
Properties for a ghost communication.
Definition ghosts.hpp:159
GhostCommunicator(boost::mpi::communicator comm, std::size_t size)
Definition ghosts.hpp:161
GhostCommunicator()=default
boost::mpi::communicator mpi_comm
Attached mpi communicator.
Definition ghosts.hpp:165
std::vector< GhostCommunication > communications
List of ghost communications.
Definition ghosts.hpp:168