Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
physical_map.cpp
Go to the documentation of this file.
1 
14 #include "layout.h"
15 
16 //====================================================================
17 static int find_coord_map(const char map_expr[], int ndim, int *map);
18 
19 //* physical rank is assigned to physical grid coord in column major order.
20 //* phys_coord[0] x phys_coord[1] x ... (fastest to slowest)
21 //* other assignment may be chosen.
22 
23 //* logical grid coord to physical rank number
24 int Communicator_impl::Layout::grid_rank(int *rank, const int *gcoord)
25 {
26  int r = 0;
27 
28  for (int i = m_ndim - 1; i >= 0; --i) {
29  int k = m_physical_to_logical[i];
30  r = r * m_grid_dims[k] + gcoord[k];
31  }
32 
33  *rank = r;
34 
35  return EXIT_SUCCESS;
36 }
37 
38 
39 //====================================================================
40 //* physical rank to logical grid coord
41 int Communicator_impl::Layout::grid_coord(int *gcoord, const int rank)
42 {
43  int r = rank;
44 
45  for (int i = 0; i < m_ndim; ++i) {
46  int k = m_physical_to_logical[i];
47 
48  gcoord[k] = r % m_grid_dims[k];
49  r /= m_grid_dims[k];
50  }
51 
52  return EXIT_SUCCESS;
53 }
54 
55 
56 //====================================================================
58 {
59  // strncpy(m_map_grid, CommonParameters::Grid_map(), sizeof(m_map_grid) / sizeof(char));
60  strncpy(m_map_grid, Communicator_impl::default_grid_map, sizeof(m_map_grid) / sizeof(char));
61 
62 #ifdef DEBUG
63  printf("DEBUG: %s: m_map_grid = \"%s\"\n", __func__, m_map_grid);
64 #endif
65 
66  // physical to logical map
67  m_physical_to_logical = new int [m_ndim];
68 
69  find_coord_map(m_map_grid, m_ndim, m_physical_to_logical);
70 
71  return EXIT_SUCCESS;
72 }
73 
74 
75 //====================================================================
77 {
78  delete [] m_physical_to_logical;
79 
80  return EXIT_SUCCESS;
81 }
82 
83 
84 //====================================================================
85 //* translate {x, y, z, t, (w)} into {0, 1, 2, 3, (4)}
86 static int find_coord_map(const char map_expr[], int ndim, int *map)
87 {
88  int len = strlen(map_expr);
89 
90  if (len != ndim) {
91  fprintf(stderr, "ERROR: find_map: length mismatch: %d, expected %d.\n", len, ndim);
92  return EXIT_FAILURE;
93  }
94 
95  for (int i = 0; i < len; ++i) {
96  char c = map_expr[i];
97  int idx = -1;
98 
99  switch (c)
100  {
101  case 'x':
102  idx = 0;
103  break;
104 
105  case 'y':
106  idx = 1;
107  break;
108 
109  case 'z':
110  idx = 2;
111  break;
112 
113  case 't':
114  idx = 3;
115  break;
116 
117  case 'w':
118  idx = 4;
119  break; // extra 5th dimension
120 
121  default:
122  fprintf(stderr, "ERROR: find_map: unknown symbol %c.\n", c);
123  return EXIT_FAILURE;
124  }
125 
126  map[i] = idx;
127  }
128 
129  return EXIT_SUCCESS;
130 }
131 
132 
133 //====================================================================
134 //============================================================END=====
static char default_grid_map[16]
static int grid_coord(int *gcoord, const int rank)
find grid coordinate corresponding to rank.
static int grid_rank(int *rank, const int *gcoord)
find rank from grid coordinate.
static int * m_grid_dims
grid dimensions in directions.
Definition: layout.h:50
static int find_coord_map(const char map_expr[], int ndim, int *map)
static int * m_physical_to_logical
map between physical and logical grid
Definition: layout.h:58
static int m_ndim
number of dimensions.
Definition: layout.h:46
static int physical_map_delete()
static int physical_map_setup()