Bridge++  Version 1.4.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 
61  // physical to logical map
62  m_physical_to_logical = new int [m_ndim];
63 
64  find_coord_map(m_map_grid, m_ndim, m_physical_to_logical);
65 
66  return EXIT_SUCCESS;
67 }
68 
69 
70 //====================================================================
72 {
73  delete [] m_physical_to_logical;
74 
75  return EXIT_SUCCESS;
76 }
77 
78 
79 //====================================================================
80 //* translate {x, y, z, t, (w)} into {0, 1, 2, 3, (4)}
81 static int find_coord_map(const char map_expr[], int ndim, int *map)
82 {
83  int len = strlen(map_expr);
84 
85  if (len != ndim) {
86  fprintf(stderr, "ERROR: find_map: length mismatch: %d, expected %d.\n", len, ndim);
87  return EXIT_FAILURE;
88  }
89 
90  for (int i = 0; i < len; ++i) {
91  char c = map_expr[i];
92  int idx = -1;
93 
94  switch (c)
95  {
96  case 'x':
97  idx = 0;
98  break;
99 
100  case 'y':
101  idx = 1;
102  break;
103 
104  case 'z':
105  idx = 2;
106  break;
107 
108  case 't':
109  idx = 3;
110  break;
111 
112  case 'w':
113  idx = 4;
114  break; // extra 5th dimension
115 
116  default:
117  fprintf(stderr, "ERROR: find_map: unknown symbol %c.\n", c);
118  return EXIT_FAILURE;
119  }
120 
121  map[i] = idx;
122  }
123 
124  return EXIT_SUCCESS;
125 }
126 
127 
128 //====================================================================
129 //============================================================END=====
static int find_coord_map(const char map_expr[], int ndim, int *map)
static int grid_coord(int *gcoord, const int rank)
static int * m_physical_to_logical
map between physical and logical grid
Definition: layout.h:46
static int m_ndim
number of dimensions.
Definition: layout.h:34
static int grid_rank(int *rank, const int *gcoord)
static int * m_grid_dims
grid dimensions in directions.
Definition: layout.h:38
static char * Grid_map()
static int physical_map_delete()
static int physical_map_setup()