| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "eckit/config/Resource.h" |
| 14 |
|
| 15 |
#include "atlas/field.h" |
| 16 |
#include "atlas/functionspace.h" |
| 17 |
#include "atlas/mesh.h" |
| 18 |
#include "atlas/parallel/mpi/mpi.h" |
| 19 |
|
| 20 |
namespace atlas { |
| 21 |
namespace debug { |
| 22 |
|
| 23 |
inline gidx_t global_index(int i = 0) { |
| 24 |
static std::vector<gidx_t> g = |
| 25 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_GLOBAL_INDEX", std::vector<gidx_t>{-1}); |
| 26 |
return g[i]; |
| 27 |
} |
| 28 |
|
| 29 |
inline gidx_t node_global_index(int i = 0) { |
| 30 |
static std::vector<gidx_t> g = |
| 31 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_NODE_GLOBAL_INDEX", std::vector<gidx_t>{-1}); |
| 32 |
return g[i]; |
| 33 |
} |
| 34 |
|
| 35 |
inline gidx_t edge_global_index(int i = 0) { |
| 36 |
static std::vector<gidx_t> g = |
| 37 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_EDGE_GLOBAL_INDEX", std::vector<gidx_t>{-1}); |
| 38 |
return g[i]; |
| 39 |
} |
| 40 |
|
| 41 |
inline gidx_t cell_global_index(int i = 0) { |
| 42 |
static std::vector<gidx_t> g = |
| 43 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_CELL_GLOBAL_INDEX", std::vector<gidx_t>{-1}); |
| 44 |
return g[i]; |
| 45 |
} |
| 46 |
|
| 47 |
inline gidx_t node_uid(int i = 0) { |
| 48 |
static std::vector<gidx_t> g = |
| 49 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_NODE_UID", std::vector<gidx_t>{-1}); |
| 50 |
return g[i]; |
| 51 |
} |
| 52 |
|
| 53 |
inline bool is_node_global_index(gidx_t x) { |
| 54 |
static std::vector<gidx_t> v = |
| 55 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_NODE_GLOBAL_INDEX", std::vector<gidx_t>()); |
| 56 |
for (gidx_t g : v) { |
| 57 |
if (x == g) |
| 58 |
return true; |
| 59 |
} |
| 60 |
return false; |
| 61 |
} |
| 62 |
|
| 63 |
inline bool is_global_index(gidx_t x) { |
| 64 |
static std::vector<gidx_t> v = |
| 65 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_GLOBAL_INDEX", std::vector<gidx_t>()); |
| 66 |
for (gidx_t g : v) { |
| 67 |
if (x == g) |
| 68 |
return true; |
| 69 |
} |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
inline bool is_edge_global_index(gidx_t x) { |
| 74 |
static std::vector<gidx_t> v = |
| 75 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_EDGE_GLOBAL_INDEX", std::vector<gidx_t>()); |
| 76 |
for (gidx_t g : v) { |
| 77 |
if (x == g) |
| 78 |
return true; |
| 79 |
} |
| 80 |
return false; |
| 81 |
} |
| 82 |
|
| 83 |
inline bool is_cell_global_index(gidx_t x) { |
| 84 |
static std::vector<gidx_t> v = |
| 85 |
eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_CELL_GLOBAL_INDEX", std::vector<gidx_t>()); |
| 86 |
for (gidx_t g : v) { |
| 87 |
if (x == g) |
| 88 |
return true; |
| 89 |
} |
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
inline bool is_node_uid(gidx_t x) { |
| 94 |
static std::vector<gidx_t> v = eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_NODE_UID", std::vector<gidx_t>()); |
| 95 |
for (gidx_t g : v) { |
| 96 |
if (x == g) |
| 97 |
return true; |
| 98 |
} |
| 99 |
return false; |
| 100 |
} |
| 101 |
|
| 102 |
inline bool is_cell_uid(gidx_t x) { |
| 103 |
static std::vector<gidx_t> v = eckit::Resource<std::vector<gidx_t>>("$ATLAS_DEBUG_CELL_UID", std::vector<gidx_t>()); |
| 104 |
for (gidx_t g : v) { |
| 105 |
if (x == g) |
| 106 |
return true; |
| 107 |
} |
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
inline int mpi_rank(int i = 0) { |
| 112 |
static std::vector<long> g = eckit::Resource<std::vector<long>>("$ATLAS_DEBUG_MPI_RANK", std::vector<long>{-1}); |
| 113 |
return g[i]; |
| 114 |
} |
| 115 |
|
| 116 |
inline int is_mpi_rank() { |
| 117 |
static std::vector<long> v = eckit::Resource<std::vector<long>>("$ATLAS_DEBUG_MPI_RANK", std::vector<long>()); |
| 118 |
static int r = mpi::rank(); |
| 119 |
for (long g : v) { |
| 120 |
if (r == g) |
| 121 |
return true; |
| 122 |
} |
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
inline int is_mpi_rank(int x) { |
| 127 |
static std::vector<long> v = eckit::Resource<std::vector<long>>("$ATLAS_DEBUG_MPI_RANK", std::vector<long>()); |
| 128 |
for (long g : v) { |
| 129 |
if (x == g) |
| 130 |
return true; |
| 131 |
} |
| 132 |
return false; |
| 133 |
} |
| 134 |
inline std::string rank_str() { |
| 135 |
static std::string s = "[" + std::to_string(mpi::rank()) + "] "; |
| 136 |
return s; |
| 137 |
} |
| 138 |
|
| 139 |
} // namespace debug |
| 140 |
} // namespace atlas |