44 #include "utils/logger.h"
45 #include "utils/stringutils.h"
61 template<
template<
class Level,
class Type>
class Container,
62 template<
class Type>
class Level,
class TypeList>
66 typedef typename TypeList::Head Head;
67 typedef typename TypeList::Tail Tail;
69 if (Head* type = dynamic_cast<Head*>(grid.
m_type)) {
71 int timeDimension = grid.
param(
"TIME_DIMENSION", -1);
74 std::string strValuePos = grid.
param(
"VALUE_POSITION",
"CELL_CENTERED");
75 ValuePosition valuePos;
76 if (strValuePos ==
"VERTEX_CENTERED")
77 valuePos = VERTEX_CENTERED;
79 valuePos = CELL_CENTERED;
80 if (strValuePos !=
"CELL_CENTERED") {
81 logWarning(grid.
m_comm.
rank()) <<
"ASAGI: Unknown value position:" << strValuePos;
82 logWarning(grid.
m_comm.
rank()) <<
"ASAGI: Assuming CELL_CENTERED";
88 *type, timeDimension, valuePos);
94 template<
template<
class Level,
class Type>
class Container,
95 template<
class Type>
class Level>
166 unsigned int blockLength[],
167 unsigned long displacements[],
173 displacements, types);
180 if (m_comm.size() > 1)
185 for (std::vector<Container*>::const_iterator it = m_containers.begin();
186 it != m_containers.end(); it++)
190 m_pointers.remove(m_id);
195 if (m_params.size() <= level)
196 m_params.resize(level+1);
199 std::string n = name;
200 utils::StringUtils::toUpper(n);
201 std::replace(n.begin(), n.end(),
'-',
'_');
204 std::string v = value;
206 && !utils::StringUtils::startsWith(n,
"BLOCK_SIZE_")) {
207 utils::StringUtils::toUpper(v);
208 std::replace(v.begin(), v.end(),
'-',
'_');
211 m_params[level][n] = v;
218 param<std::string>(
"NUMA_COMMUNICATION",
"ON") !=
"OFF");
226 int blockSizes[MAX_DIMENSIONS];
227 for (
unsigned int i = 0; i < MAX_DIMENSIONS; i++) {
228 std::string sizeName =
"BLOCK_SIZE_" + utils::StringUtils::toString(i);
229 blockSizes[i] = param(sizeName.c_str(), 0, level);
232 unsigned int cacheSize = param(
"CACHE_SIZE", 128u, level);
234 logError() <<
"ASAGI: Cache size cannot be 0.";
235 err = m_containers[m_numa.domainId()]->init(filename,
236 param(
"VARIABLE",
"z", level),
239 param(
"CACHE_HAND_SPREAD", -1, level),
255 unsigned long counter = 0;
258 for (std::vector<Container*>::const_iterator it = m_containers.begin();
259 it != m_containers.end(); it++)
260 counter += (*it)->getCounter(type);
272 m_id = m_pointers.add(
this);
285 CACHE_MPITHREAD_NUMA,
293 FULL_MPITHREAD_NUMACACHE,
294 FULL_MPIWIN_NUMACACHE,
297 } containerType = UNKNOWN;
318 std::string mpiType = param(
"MPI_COMMUNICATION",
"WINDOW");
319 #ifdef THREADSAFE_MPI
320 if (mpiType ==
"THREAD") {
321 logWarning(m_comm.rank()) <<
"ASAGI: Communication thread requires a thread-safe MPI library";
324 #endif // THREADSAFE_MPI
325 if (m_comm.size() == 1)
328 else if (mpiType ==
"OFF")
330 setComm(MPI_COMM_SELF);
335 std::string numaType = param(
"NUMA_COMMUNICATION",
"OFF");
336 if (numaType !=
"OFF")
337 logWarning(m_comm.rank()) <<
"ASAGI: NUMA communication could not be enabled because the"
338 " ASAGI is not compiled with NUMA support.";
339 #else // ASAGI_NONUMA
340 std::string numaType = param(
"NUMA_COMMUNICATION",
"ON");
341 #endif // ASAGI_NONUMA
342 if (m_numa.totalDomains() == 1)
346 std::string gridType = param(
"GRID",
"FULL");
347 if (gridType ==
"CACHE") {
348 if (mpiType ==
"OFF") {
349 if (numaType ==
"OFF")
350 containerType = CACHE_NUMA;
352 containerType = CACHE;
353 }
else if (mpiType ==
"THREAD") {
354 if (numaType ==
"OFF")
355 containerType = CACHE_MPITHREAD;
357 containerType = CACHE_MPITHREAD_NUMA;
359 if (numaType ==
"OFF")
360 containerType = CACHE_MPIWIN;
362 containerType = CACHE_MPIWIN_NUMA;
364 }
else if (gridType ==
"PASS_THROUGH")
365 containerType = PASS_THROUGH;
367 if (gridType !=
"FULL") {
368 logWarning(m_comm.rank()) <<
"ASAGI: Unknown grid type:" << gridType;
369 logWarning(m_comm.rank()) <<
"ASAGI: Assuming FULL";
372 if (mpiType ==
"OFF") {
373 if (numaType ==
"OFF")
374 containerType = FULL;
376 containerType = FULL_NUMA;
377 }
else if (mpiType ==
"THREAD") {
378 if (numaType ==
"OFF")
379 containerType = FULL_MPITHREAD;
380 else if (numaType ==
"CACHE")
381 containerType = FULL_MPITHREAD_NUMACACHE;
383 containerType = FULL_MPITHREAD_NUMA;
385 if (numaType ==
"OFF")
386 containerType = FULL_MPIWIN;
387 else if (numaType ==
"CACHE")
388 containerType = FULL_MPIWIN_NUMACACHE;
390 containerType = FULL_MPIWIN_NUMA;
395 m_containers.resize(m_numa.totalDomains());
396 for (std::vector<Container*>::iterator it = m_containers.begin();
397 it != m_containers.end(); it++) {
398 switch (containerType) {
405 case CACHE_MPITHREAD:
412 logError() <<
"ASAGI: These options require MPI-3 support";
415 case CACHE_MPITHREAD_NUMA:
418 case CACHE_MPIWIN_NUMA:
422 logError() <<
"ASAGI: These options require MPI-3 support";
437 case FULL_MPITHREAD_NUMA:
440 case FULL_MPIWIN_NUMA:
443 case FULL_MPITHREAD_NUMACACHE:
446 case FULL_MPIWIN_NUMACACHE:
466 if (level >= m_params.size())
469 std::map<std::string, std::string>::const_iterator it = m_params[level].find(name);
470 if (it == m_params[level].end())
473 return utils::StringUtils::parse<T>(it->second,
true);
Type * createStruct(unsigned int count, unsigned int blockLength[], unsigned long displacements[], asagi::Grid::Type types[])
void setParam(const char *name, const char *value, unsigned int level=0)
Changes a grid parameter.
static grid::Container * createContainer(Grid &grid)
unsigned long getCounter(const char *name, unsigned int level=0)
T param(const char *name, T defaultValue, unsigned int level=0) const
static CounterType name2type(const char *name)
static fortran::PointerArray< Grid > m_pointers
asagi::Grid::Error open(const char *filename, unsigned int level=0)
Loads values from a NetCDF file.
Grid(asagi::Grid::Type type, bool isArray=false)