Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Classes | Namespaces | Functions
MultiApp.h File Reference

Go to the source code of this file.

Classes

class  libMesh::NumericVector< T >
 
struct  LocalRankConfig
 Holds app partitioning information relevant to the a particular rank for a multiapp scenario. More...
 
class  SubAppBackups
 Helper class for holding Sub-app backups. More...
 
class  MultiApp
 A MultiApp represents one or more MOOSE applications that are running simultaneously. More...
 

Namespaces

 libMesh
 The following methods are specializations for using the libMesh::Parallel::packed_range_* routines for std::strings.
 
 libMesh::MeshTools
 

Functions

LocalRankConfig rankConfig (processor_id_type rank, processor_id_type nprocs, dof_id_type napps, processor_id_type min_app_procs, processor_id_type max_app_procs, bool batch_mode=false)
 Returns app partitioning information relevant to the given rank for a multiapp scenario with the given number of apps (napps) and parallel/mpi procs (nprocs). More...
 
void dataStore (std::ostream &stream, SubAppBackups &backups, void *context)
 
void dataLoad (std::istream &stream, SubAppBackups &backups, void *context)
 

Function Documentation

◆ dataLoad()

void dataLoad ( std::istream &  stream,
SubAppBackups backups,
void context 
)

Definition at line 1489 of file MultiApp.C.

1490 {
1491  MultiApp * multi_app = static_cast<MultiApp *>(context);
1492  mooseAssert(multi_app, "Not set");
1493 
1494  dataLoad(stream, static_cast<std::vector<std::unique_ptr<Backup>> &>(backups), nullptr);
1495 
1496  multi_app->restore();
1497 }
virtual void restore(bool force=true)
Restore the state of every Sub App.
Definition: MultiApp.C:756
void dataLoad(std::istream &stream, SubAppBackups &backups, void *context)
Definition: MultiApp.C:1489
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition: MultiApp.h:112

◆ dataStore()

void dataStore ( std::ostream &  stream,
SubAppBackups backups,
void context 
)

Definition at line 1478 of file MultiApp.C.

1479 {
1480  MultiApp * multi_app = static_cast<MultiApp *>(context);
1481  mooseAssert(multi_app, "Not set");
1482 
1483  multi_app->backup();
1484 
1485  dataStore(stream, static_cast<std::vector<std::unique_ptr<Backup>> &>(backups), nullptr);
1486 }
virtual void backup()
Save off the state of every Sub App.
Definition: MultiApp.C:741
void dataStore(std::ostream &stream, SubAppBackups &backups, void *context)
Definition: MultiApp.C:1478
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition: MultiApp.h:112

◆ rankConfig()

LocalRankConfig rankConfig ( processor_id_type  rank,
processor_id_type  nprocs,
dof_id_type  napps,
processor_id_type  min_app_procs,
processor_id_type  max_app_procs,
bool  batch_mode = false 
)

Returns app partitioning information relevant to the given rank for a multiapp scenario with the given number of apps (napps) and parallel/mpi procs (nprocs).

min_app_procs and max_app_procs define the min and max number of procs that must/can be used in parallel to run a given (sub)app. batch_mode affects whether 1 subapp is assigned per rank to be re-used to run each of the (napps) simulations or whether 1 subapp is created for each napps simulation (globally).

Each proc calls this function in order to determine which (sub)apps among the global list of all subapps for a multiapp should be run by the given rank.

Definition at line 1285 of file MultiApp.C.

Referenced by Sampler::constructRankConfig(), and MultiApp::init().

1291 {
1292  if (min_app_procs > nprocs)
1293  mooseError("minimum number of procs per app is higher than the available number of procs");
1294  else if (min_app_procs > max_app_procs)
1295  mooseError("minimum number of procs per app must be lower than the max procs per app");
1296 
1297  mooseAssert(rank < nprocs, "rank must be smaller than the number of procs");
1298 
1299  // A "slot" is a group of procs/ranks that are grouped together to run a
1300  // single (sub)app/sim in parallel.
1301 
1302  const processor_id_type slot_size =
1303  std::max(std::min(cast_int<processor_id_type>(nprocs / napps), max_app_procs), min_app_procs);
1304  const processor_id_type nslots = std::min(
1305  nprocs / slot_size,
1306  cast_int<processor_id_type>(std::min(
1307  static_cast<dof_id_type>(std::numeric_limits<processor_id_type>::max()), napps)));
1308  mooseAssert(nprocs >= (nslots * slot_size),
1309  "Ensure that leftover procs is represented by an unsigned type");
1310  const processor_id_type leftover_procs = nprocs - nslots * slot_size;
1311  const dof_id_type apps_per_slot = napps / nslots;
1312  const dof_id_type leftover_apps = napps % nslots;
1313 
1314  std::vector<int> slot_for_rank(nprocs);
1315  processor_id_type slot = 0;
1316  processor_id_type procs_in_slot = 0;
1317  for (processor_id_type rankiter = 0; rankiter <= rank; rankiter++)
1318  {
1319  if (slot < nslots)
1320  slot_for_rank[rankiter] = cast_int<int>(slot);
1321  else
1322  slot_for_rank[rankiter] = -1;
1323  procs_in_slot++;
1324  // this slot keeps growing until we reach slot size plus possibly an extra
1325  // proc if there were any leftover from the slotization of nprocs - this
1326  // must also make sure we don't go over max app procs.
1327  if (procs_in_slot == slot_size + 1 * (slot < leftover_procs && slot_size < max_app_procs))
1328  {
1329  procs_in_slot = 0;
1330  slot++;
1331  }
1332  }
1333 
1334  if (slot_for_rank[rank] < 0)
1335  // ranks assigned a negative slot don't have any apps running on them.
1336  return {0, 0, 0, 0, false, 0};
1337  const processor_id_type slot_num = cast_int<processor_id_type>(slot_for_rank[rank]);
1338 
1339  const bool is_first_local_rank = rank == 0 || (slot_for_rank[rank - 1] != slot_for_rank[rank]);
1340  const dof_id_type n_local_apps = apps_per_slot + 1 * (slot_num < leftover_apps);
1341 
1342  processor_id_type my_first_rank = 0;
1343  for (processor_id_type rankiter = rank; rankiter > 0; rankiter--)
1344  if (slot_for_rank[rank] != slot_for_rank[rankiter])
1345  {
1346  my_first_rank = cast_int<processor_id_type>(slot_for_rank[rankiter + 1]);
1347  break;
1348  }
1349 
1350  dof_id_type app_index = 0;
1351  for (processor_id_type slot = 0; slot < slot_num; slot++)
1352  {
1353  const dof_id_type num_slot_apps = apps_per_slot + 1 * (slot < leftover_apps);
1354  app_index += num_slot_apps;
1355  }
1356 
1357  if (batch_mode)
1358  return {n_local_apps, app_index, 1, slot_num, is_first_local_rank, my_first_rank};
1359  return {n_local_apps, app_index, n_local_apps, app_index, is_first_local_rank, my_first_rank};
1360 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
auto max(const L &left, const R &right)
uint8_t processor_id_type
auto min(const L &left, const R &right)
uint8_t dof_id_type