Skip to content

Commit 7e1c4f9

Browse files
committed
Merge branch 'feature/handlers' of github.com:lisataldir/TCLB into feature/handlers
2 parents 78d8a42 + eee8d8f commit 7e1c4f9

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/ArbConnectivity.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ struct ArbLatticeConnectivity {
1616
std::unique_ptr<Index[]> og_index;
1717
std::unique_ptr<Index[]> nbrs;
1818
std::unique_ptr<ZoneIndex[]> zones_per_node;
19+
std::vector<Index> cart_index;
1920
std::vector<ZoneIndex> zones;
2021
double grid_size{};
22+
int nx, ny, nz; // total region
2123

2224
ArbLatticeConnectivity() = default;
2325
ArbLatticeConnectivity(size_t chunk_begin_, size_t chunk_end_, size_t num_nodes_global_, size_t Q_)
@@ -28,7 +30,8 @@ struct ArbLatticeConnectivity {
2830
coords(std::make_unique<double[]>(3 * (chunk_end_ - chunk_begin_))),
2931
og_index(std::make_unique<Index[]>(chunk_end_ - chunk_begin_)),
3032
nbrs(std::make_unique<Index[]>((chunk_end_ - chunk_begin_) * Q)),
31-
zones_per_node(std::make_unique<ZoneIndex[]>(chunk_end_ - chunk_begin_)) {
33+
zones_per_node(std::make_unique<ZoneIndex[]>(chunk_end_ - chunk_begin_)),
34+
cart_index(chunk_end_ - chunk_begin_) {
3235
zones.reserve(getLocalSize());
3336
}
3437

@@ -53,6 +56,8 @@ struct ArbLatticeConnectivity {
5356

5457
double& coord(size_t dim, size_t local_node_ind) { return coords[local_node_ind + dim * getLocalSize()]; }
5558
double coord(size_t dim, size_t local_node_ind) const { return coords[local_node_ind + dim * getLocalSize()]; }
59+
Index& cartesian_ind(size_t local_node_ind) { return cart_index[local_node_ind]; }
60+
Index cartesian_ind(size_t local_node_ind) const { return cart_index[local_node_ind]; }
5661
Index& neighbor(size_t q, size_t local_node_ind) { return nbrs[local_node_ind + q * getLocalSize()]; }
5762
Index neighbor(size_t q, size_t local_node_ind) const { return nbrs[local_node_ind + q * getLocalSize()]; }
5863

src/ArbLattice.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ void ArbLattice::readFromCxn(const std::string& cxn_path) {
167167
file >> grid_size;
168168
check_file_ok("Failed to read section: GRID_SIZE");
169169

170+
// Total region
171+
file >> word;
172+
check_file_ok("Failed to read section header: TOTAL_REGION");
173+
check_expected_word("TOTAL_REGION", word);
174+
int nx, ny, nz;
175+
file >> nx >> ny >> nz;
176+
check_file_ok("Failed to read section: TOTAL_REGION");
177+
170178
// Labels present in the .cxn file
171179
const auto labels = process_section("NODE_LABELS", [&file](size_t n_labels) {
172180
std::vector<std::string> retval(n_labels);
@@ -177,24 +185,30 @@ void ArbLattice::readFromCxn(const std::string& cxn_path) {
177185

178186
// Nodes header
179187
process_section("NODES", [&](size_t num_nodes_global) {
180-
// Compute the current rank's offset and number of nodes to read
188+
// Compute the current ranks offset and number of nodes to read
181189
const auto chunk_offsets = computeInitialNodeDist(num_nodes_global, static_cast<size_t>(comm_size));
182190
const auto chunk_begin = static_cast<size_t>(chunk_offsets[comm_rank]), chunk_end = static_cast<size_t>(chunk_offsets[comm_rank + 1]);
183191
const auto num_nodes_local = chunk_end - chunk_begin;
184192

185193
connect = ArbLatticeConnectivity(chunk_begin, chunk_end, num_nodes_global, Q);
186194
connect.grid_size = grid_size;
195+
connect.nx = nx;
196+
connect.ny = ny;
197+
connect.nz = nz;
187198

188199
// Skip chunk_begin + 1 (header) newlines
189200
for (size_t i = 0; i != chunk_begin + 1; ++i) file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
190-
check_file_ok("Failed to skip ahead to this rank's chunk");
201+
check_file_ok("Failed to skip ahead to this ranks chunk");
191202

192203
// Parse node data
193204
std::vector<long> nbrs_in_file(q_provided.size());
194205
for (size_t local_node_ind = 0; local_node_ind != num_nodes_local; ++local_node_ind) {
195206
// Read coords
196207
file >> connect.coord(0, local_node_ind) >> connect.coord(1, local_node_ind) >> connect.coord(2, local_node_ind);
197208

209+
// Read cartesian index
210+
file >> connect.cartesian_ind(local_node_ind);
211+
198212
// Read neighbors, map to local (required) ones
199213
for (auto& nbr : nbrs_in_file) file >> nbr;
200214
size_t j = 0;

src/CartLatticeLauncher.hpp.Rt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ public:
255255

256256
CudaDeviceFunction void Execute() const {
257257
using LA = CartLatticeAccessAll;
258-
int x = CudaBlock.x + small.dx;
259-
int y = CudaBlock.y + small.dy;
260-
int z = CudaBlock.z + small.dz;
258+
int x = (CudaBlock.x + small.dx) %container.nx;
259+
int y = (CudaBlock.y + small.dy) %container.ny;
260+
int z = (CudaBlock.z + small.dz) %container.nz;
261261
LA acc(x, y, z, container); <?R
262262
if (q$adjoint) { ?>
263263
Node< LA, Adjoint, NoGlobals, Get > now(acc, data); <?R

src/toArb.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ static int writeArbLatticeHeader(std::fstream& file, const lbRegion& region, siz
6161
file << "OFFSET_DIRECTIONS " << Model_m::offset_directions.size() << '\n';
6262
for (const auto [x, y, z] : Model_m::offset_directions) file << x << ' ' << y << ' ' << z << '\n';
6363
file << "GRID_SIZE " << grid_size << '\n';
64+
file << "TOTAL_REGION " << region.nx << ' ' << region.ny << ' ' << region.nz << '\n';
6465
file << "NODE_LABELS " << model.nodetypeflags.size() + zone_map.size() << '\n';
6566
for (const auto& ntf : model.nodetypeflags) file << ntf.name << '\n';
6667
for (const auto& [name, zf] : zone_map) file << "_Z_" << name << '\n';
@@ -93,6 +94,9 @@ static int writeArbLatticeNodes(const Geometry& geo,
9394
const double z_coord = (static_cast<double>(z) + .5) * spacing;
9495
file << x_coord << ' ' << y_coord << ' ' << z_coord << ' ';
9596

97+
// Cartesian index
98+
file << current_lin_pos << ' ';
99+
96100
// Neighbors
97101
for (const auto [dx, dy, dz] : Model_m::offset_directions) {
98102
const auto lin_pos_offset = linPosBoundschecked(x + dx, y + dy, z + dz, nx, ny, nz);

0 commit comments

Comments
 (0)