RepastHPC
2.3.1
|
The ValueLayerND class is an N-dimensional layer of values. More...
#include <ValueLayerND.h>
Public Member Functions | |
ValueLayerND (vector< int > processesPerDim, GridDimensions globalBoundaries, int bufferSize, bool periodic, T initialValue=0, T initialBufferZoneValue=0) | |
virtual void | initialize (T initialValue, bool fillBufferZone=false, bool fillLocal=true) |
Inherited from AbstractValueLayerND. | |
virtual void | initialize (T initialLocalValue, T initialBufferZoneValue) |
Inherited from AbstractValueLayerND. | |
virtual T | addValueAt (T val, Point< int > location, bool &errFlag) |
Inherited from AbstractValueLayerND. | |
virtual T | addValueAt (T val, vector< int > location, bool &errFlag) |
Inherited from AbstractValueLayerND. | |
virtual T | setValueAt (T val, Point< int > location, bool &errFlag) |
Inherited from AbstractValueLayerND. | |
virtual T | setValueAt (T val, vector< int > location, bool &errFlag) |
Inherited from AbstractValueLayerND. | |
virtual T | getValueAt (Point< int > location, bool &errFlag) |
Inherited from AbstractValueLayerND. | |
virtual T | getValueAt (vector< int > location, bool &errFlag) |
Inherited from AbstractValueLayerND. | |
virtual void | synchronize () |
Inherited from AbstractValueLayerND. | |
void | write (string fileLocation, string filetag, bool writeSharedBoundaryAreas=false) |
Write the values in this ValueLayer to a .csv file. More... | |
Public Member Functions inherited from repast::AbstractValueLayerND< T > | |
virtual bool | isInLocalBounds (vector< int > coords) |
Returns true only if the coordinates given are within the local boundaries. More... | |
virtual bool | isInLocalBounds (Point< int > location) |
const GridDimensions & | getLocalBoundaries () |
Gets the local boundaries for this process's part of the value layer. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from repast::AbstractValueLayerND< T > | |
static int | instanceCount = 0 |
Protected Member Functions inherited from repast::AbstractValueLayerND< T > | |
AbstractValueLayerND (vector< int > processesPerDim, GridDimensions globalBoundaries, int bufferSize, bool periodic) | |
Constructor. More... | |
vector< int > | getIndexes (vector< int > location, bool isSimplified=false) |
Gets a vector of the indexed locations. More... | |
int | getIndex (vector< int > location, bool isSimplified=false) |
Given a location in global simulation coordinates, get the offset from the global base pointer to the position in the global array representing that location. More... | |
int | getIndex (Point< int > location) |
Given a location in global simulation coordinates, get the offset from the global base pointer to the position in the global array representing that location. More... | |
Protected Attributes inherited from repast::AbstractValueLayerND< T > | |
CartesianTopology * | cartTopology |
GridDimensions | localBoundaries |
int | length |
int | numDims |
bool | globalSpaceIsPeriodic |
vector< int > | places |
vector< int > | strides |
vector< DimensionDatum< T > > | dimensionData |
RankDatum * | neighborData |
int | neighborCount |
MPI_Request * | requests |
int | instanceID |
int | syncCount |
The ValueLayerND class is an N-dimensional layer of values.
The most complex part of the ValueLayerND class is the interaction with MPI. Cross-process synchronization requires that blocks of cells (technically volumes in N-space) be sent across processes. MPI Derived Datatypes are used to achieve this.
The memory for the N-Dimensional array is organized as a nested loop. Assume that the dimensions for the array are d1, d2, d3 ... dN. The extent of the grid in each dimension is e1, e2, e3 ... eN. Note that this includes both the space within the local boundaries and the adjacent buffer zones. For convenience we pre-calculate a vector M1, M2, M3 ... MN of multipliers; each entry is equal to the product of all the extents of lower-numbered dimensions, with M1 = 1. The address of a cell a locations l1, l2, l3 ... lN will be:
l1 * M1 + l2 * M2 + l3 * M3 ... lN * MN
A volume in this space will not occupy a contiguous block of memory. It would be more convenient for the MPI call if it did. However, the MPI specification indicates that derived data types can be used to define complex regions of memory; the MPI implementation can optimize the sending and receiving of these.
In this class, an MPI Datatype is defined to represent the volume of space being sent to and received from each of the 3N - 1 adjacent processes.
One important note is that the send and receive data types for a given exchange partner will be identical; only the starting pointer need be changed to switch from sending to receiving.
(It should be noted that MPI allows these data types to 'match' if they are structurally compatible. They need not actually be identical. So, consider a send/receive pair where one of the pair is against the global simulation boundaries but the other is not. The actual pattern of loops and steps that creates the send will be different from the pattern that creates the receive, but MPI will recognize that these are 'matchable' and will perform the communication.)
The data type can be defined recursively using MPI's HVector function for all types except the innermost, which is a contiguous block of double values.
The memory space allocated by this object includes buffer zones on all 2N sides and all intercardinal directions, even if the space is adjacent to a strict boundary edge.
void repast::ValueLayerND< T >::write | ( | string | fileLocation, |
string | filetag, | ||
bool | writeSharedBoundaryAreas = false |
||
) |
Write the values in this ValueLayer to a .csv file.
The file format is:
Dim_0,Dim_1,Dim_2,VAL 0,0,0,100 0,0,1,200
The column header indicates the dimensionl the value in the 'VAL' column is the value in the ValueLayer at the coordinates specified by the values in the first N columns.
In many common situations, many cells will contain zero; to keep file sizes small, zeros are not written.
fileLocation | path to the file location for output |
filetag | infix for the file name @writeSharedBoundaryAreas if true, the data output will include the adjacent processes' buffer zones as they exist in this array; if false, these will be omitted |