HILA
Loading...
Searching...
No Matches
setup_layout_simple.cpp
1/// This routine decides how the lattice is distributed among
2/// the nodes. This is the generic version, which just
3/// throws the system to as "square"" blocks as possible.
4/// TODO:
5/// First tries to divide the lattice so that every node has
6/// the same size, but if that fails then allow different
7/// division to one direction
8
9#include "plumbing/defs.h"
10#include "plumbing/lattice.h"
11
12/***************************************************************/
13
14/* number of primes to be used in factorization */
15#define NPRIMES 9
16static int prime[NPRIMES] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
17
18/* Set up now squaresize and nsquares - arrays
19 * Print info to outf as we proceed
20 */
21
22void lattice_struct::setup_layout() {
23 int i, msize, dir, nfactors[NPRIMES], nodesiz[NDIM];
24
25 hila::out0 << "Standard lattice layout:\n " << NDIM << " dimensions\n";
26
27 /* Figure out dimensions of hyperrectangle - this version ensures all are same size */
28
29 if (l_volume % hila::number_of_nodes()) {
30 hila::out0 << " No hope of laying out the lattice using " << hila::number_of_nodes()
31 << " nodes\n";
33 }
34
35 /* Factorize the node number in primes
36 * These factors must be used in slicing the lattice!
37 */
39 for (int n = 0; n < NPRIMES; n++) {
40 nfactors[n] = 0;
41 while (i % prime[n] == 0) {
42 i /= prime[n];
43 nfactors[n]++;
44 }
45 }
46 if (i != 1) {
47 hila::out0 << " Cannot factorize " << hila::number_of_nodes() << " nodes with primes up to "
48 << prime[NPRIMES - 1] << '\n';
50 }
51
52 for (i = 0; i < NDIM; i++) {
53 nodesiz[i] = size(i);
54 nodes.n_divisions[i] = 1;
55 }
56
57 for (int n = NPRIMES - 1; n >= 0; n--)
58 for (i = 0; i < nfactors[n]; i++) {
59 /* figure out which direction to divide -- start from the largest prime,
60 * because we don't want this to be last divisor! (would probably wind up with
61 * size 1)
62 */
63
64 // find largest divisible dimension of h-cubes - start from last, because
65 // SF and spatial FFT.
66 for (msize = 1, dir = 0; dir < NDIM; dir++)
67 if (nodesiz[dir] > msize && nodesiz[dir] % prime[n] == 0)
68 msize = nodesiz[dir];
69
70 // if one direction with largest dimension has already been
71 // divided, divide it again. Otherwise divide first direction
72 // with largest dimension.
73
74 // Switch here to first divide along t-direction, in
75 // order to
76 // a) minimize spatial blocks, for FFT
77 // b) In sf t-division is cheaper (1 non-communicating slice)
78
79 for (dir = NDIM - 1; dir >= 0; dir--)
80 if (nodesiz[dir] == msize && nodes.n_divisions[dir] > 1 &&
81 nodesiz[dir] % prime[n] == 0)
82 break;
83
84 /* If not previously sliced, take one direction to slice */
85 if (dir < 0)
86 for (dir = NDIM - 1; dir >= 0; dir--)
87 if (nodesiz[dir] == msize && nodesiz[dir] % prime[n] == 0)
88 break;
89
90 if (dir < 0) {
91 /* This cannot happen */
92 hila::out0 << "CANNOT HAPPEN! in setup_layout_simple\n";
94 }
95
96 /* Now slice it */
97 nodesiz[dir] /= prime[n];
98 nodes.n_divisions[dir] *= prime[n];
99 }
100
101 // set up struct nodes variables
102 nodes.number = hila::number_of_nodes();
103 foralldir(dir) {
104 nodes.divisors[dir].resize(nodes.n_divisions[dir] + 1);
105 // trivial, evenly spaced divisors -- note: last element == size(dir)
106 for (int i = 0; i <= nodes.n_divisions[dir]; i++)
107 nodes.divisors[dir].at(i) = i * nodesiz[dir];
108 }
109
110
111 // For MPI, remap the nodes for periodic torus
112 // in the desired manner
113 // we have at least 2 options:
114 // map_node_layout_trivial.c
115 // map_node_layout_block2.c - for 2^n n.n. blocks
116
117 nodes.create_remap();
118
119 if (hila::myrank() == 0) {
120 hila::out0 << "\n Sites on node: ";
121 foralldir(dir) {
122 if (dir > 0) {
123 hila::out0 << " x ";
124 }
125 hila::out0 << nodesiz[dir];
126 }
127 hila::out0 << "\n Processor layout: ";
128 foralldir(dir) {
129 if (dir > 0) {
130 hila::out0 << " x ";
131 }
132 hila::out0 << nodes.n_divisions[dir];
133 }
134 hila::out0 << '\n';
135 }
136}
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78
This file defines all includes for HILA.
int myrank()
rank of this node
Definition com_mpi.cpp:235
int number_of_nodes()
how many nodes there are
Definition com_mpi.cpp:246
std::ostream out0
This writes output only from main process (node 0)
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...