/[escript]/trunk/ripley/src/blocktools.h
ViewVC logotype

Annotation of /trunk/ripley/src/blocktools.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4657 - (hide annotations)
Thu Feb 6 06:12:20 2014 UTC (5 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 7060 byte(s)
I changed some files.
Updated copyright notices, added GeoComp.



1 jfenwick 4650 /*****************************************************************************
2     *
3     * Copyright (c) 2014 by University of Queensland
4     * http://www.uq.edu.au
5     *
6     * Primary Business: Queensland, Australia
7     * Licensed under the Open Software License version 3.0
8     * http://www.opensource.org/licenses/osl-3.0.php
9     *
10     * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 jfenwick 4657 * Development 2012-2013 by School of Earth Sciences
12     * Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 jfenwick 4650 *
14     *****************************************************************************/
15    
16    
17     #include <vector>
18    
19    
20     /* This file contains two main classes for dealing with a large 3D region which has been divided
21     into a 3D Grid of Blocks (usually to be distributed). Each block is divided into 27 subblocks.
22     The first and last subblocks in each dimension are cubes.
23    
24     class Block mangages a single block. It has methods for copying between a flat array (storing
25     all the values in the 3D block) and buffers storing individual subblocks.
26     These buffers can be used to transfer individual subblocks to other blocks (using some external
27     means).
28    
29     class BlockGrid deals with the position of a given block in relation to the rest of the blocks
30     in the grid. (In an MPI setting, there would be one block per rank.)
31     It also required transfers of subblocks into and out of the block in order to make the whole
32     (global) array consistant.
33    
34     Each block has a region "inset" wide in from each edge which is shared with nieghbouring blocks.
35     Where these regions overlap with another block, the block closest to block 0,0,0 are used.
36     Or more precisely, values move left->right then lowy->highy and finally lowz -> highz.
37    
38     Please don't mix external calls into this file, it may be useful to separate it for
39     debugging purposes.
40    
41     Types required:
42     neighbourID_t - Stores the label of a neighbouring block.
43     In an MPI setting, this will be the type used refer to ranks
44     coord_t - Stores a position of a block in the grid of blocks (it could be
45     within one dimension or overall in a flat structure.
46     It is not (necessarily) the same as neighbourID_t because
47     coord_t should be _unsigned_ and there is no guarantee
48     that neighbourID_t will even be an integral type.
49     */
50    
51     #ifdef ESYS_MPI
52 jfenwick 4651 #include <esysUtils/Esys_MPI.h>
53 jfenwick 4650 typedef Esys_MPI_rank neighbourID_t; // This should be the MPI_rank type
54     typedef unsigned coord_t; // if we ever get more than 2^32 ranks, we have other problems
55    
56    
57     #else
58    
59     typedef int neighbourID_t; // This should be the MPI_rank type
60     typedef unsigned coord_t; // if we ever get more than 2^32 ranks, we have other problems
61    
62     #endif
63    
64    
65     typedef std::pair<neighbourID_t, int> neighpair;
66     typedef std::vector<neighpair> neighbourvector;
67    
68    
69    
70     typedef struct
71     {
72     public:
73     neighbourID_t sourceID; // ranks involved in communication
74     neighbourID_t destID;
75     int tag;
76 jfenwick 4652 unsigned char srcbuffid; // number of buffer to use for coms
77     unsigned char destbuffid;
78 jfenwick 4650 } message;
79    
80     typedef std::vector<message> messvec;
81    
82    
83    
84     class BlockGrid
85     {
86     public:
87     BlockGrid(coord_t maxx, coord_t maxy, coord_t maxz);
88    
89     neighbourID_t getNID(coord_t x, coord_t y, coord_t z) const;
90    
91    
92     // generate all incoming com messages for this block.
93     // for each subblock (27 of them), there may be an x, y, z direction to search in
94     void generateInNeighbours(coord_t blockx, coord_t blocky, coord_t blockz, messvec& v);
95    
96    
97     // generate all outgoing com messages for this block
98     void generateOutNeighbours(coord_t blockx, coord_t blocky, coord_t blockz, messvec& v);
99     private:
100     coord_t xmax;
101     coord_t ymax;
102     coord_t zmax;
103    
104     };
105    
106     /* Do not ask about buffers for sub-block 1,1,1 (also known as #13)
107     They do not exist, such buffers woudl be:
108     1) big
109     2) unnecessary since the centre sub-block is not sent anywhere
110    
111     Note that this class does not deal with data transfer between blocks
112     Sub-blocks are copied to and from buffers. Other code is required to
113     actually move the data.
114     */
115     class Block
116     {
117     public:
118    
119     // s? specifiy the [local] size (in points) of each dimension
120     Block(size_t sx, size_t sy, size_t sz, size_t inset, size_t xmidlen, size_t ymidlen, size_t zmidlen);
121    
122     ~Block();
123    
124     // Out buffers are loaded with the contents of the flat array and are
125     // to be sent to other blocks
126 jfenwick 4652 double* getOutBuffer(unsigned char subx, unsigned char suby, unsigned char subz);
127     double* getOutBuffer(unsigned char bid);
128 jfenwick 4650
129     // In buffers are populated from external communications
130     // and copied back to teh flat array
131 jfenwick 4652 double* getInBuffer(unsigned char subx, unsigned char suby, unsigned char subz);
132     double* getInBuffer(unsigned char bid);
133 jfenwick 4650
134     // return number of doubles in the given block
135 jfenwick 4652 size_t getBuffSize(unsigned char subx, unsigned char suby, unsigned char subz);
136     size_t getBuffSize(unsigned char bid);
137 jfenwick 4650
138     // where does the subblock specified start in a source array
139 jfenwick 4652 size_t startOffset(unsigned char subx, unsigned char suby, unsigned char subz);
140 jfenwick 4650
141     // debug only
142 jfenwick 4652 void displayBlock(unsigned char subx, unsigned char suby, unsigned char subz, bool out);
143 jfenwick 4650
144     // Copy a 3d region from a flat array into a buffer
145 jfenwick 4652 void copyToBuffer(unsigned char buffid, double* src);
146 jfenwick 4650
147     // Copy a 3d region from a buffer into a flat array
148 jfenwick 4652 void copyFromBuffer(unsigned char buffid, double* dest);
149 jfenwick 4650
150    
151     void copyAllToBuffer(double* src);
152    
153     void copyUsedFromBuffer(double* dest);
154    
155 jfenwick 4652 void setUsed(unsigned char buffid);
156 jfenwick 4650
157     private:
158    
159     // determines the dimensions of each subblock
160     void populateDimsTable();
161     void populateOffsetTable(size_t inset, size_t xmidlen, size_t ymidlen, size_t zmidlen);
162     void createBuffArrays(double* startaddress, double* buffptr[27], size_t inset, size_t xmidlen, size_t ymidlen, size_t zmidlen);
163    
164    
165    
166     double* inbuff;
167     double* outbuff;
168     size_t buffoffsets[27]; // offsets of the various blocks within the buffer arrays
169     size_t flatoffsets[27]; // starting point of each block within a flat array
170     bool used[27];
171     size_t dims[27][3]; // dimension of each subblock
172     size_t sx;
173     size_t sy;
174     size_t sz;
175     size_t inset;
176     size_t xmidlen;
177     size_t ymidlen;
178     size_t zmidlen;
179     double* inbuffptr[27];
180     double* outbuffptr[27];
181    
182    
183    
184     };
185    
186     // Returns the MPI message tag to use for a transfer between the two subblocks
187 jfenwick 4652 int getTag(unsigned char sourcex, unsigned char sourcey, unsigned char sourcez, unsigned char targetx, unsigned char targety, unsigned char targetz);
188 jfenwick 4650
189     // computes the tag based on the destination and the direction it comes from
190     // the booleans indicate whether a negative shift in that direction is required
191 jfenwick 4652 int getTag(unsigned char destx, unsigned char desty, unsigned char destz, bool deltax, bool deltay, bool deltaz);
192 jfenwick 4650
193    
194     // the booleans indicate whether a negative shift in that direction is required
195 jfenwick 4652 unsigned char getSrcBuffID(unsigned char destx, unsigned char desty, unsigned char destz, bool deltax, bool deltay, bool deltaz);
196 jfenwick 4650
197    

  ViewVC Help
Powered by ViewVC 1.1.26