https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
MultiApp.h File Reference

Go to the source code of this file.

Classes

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

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

Functions

template<>
void dataStore (std::ostream &stream, LocalRankConfig &v, void *context)
 
template<>
void dataLoad (std::istream &stream, LocalRankConfig &v, void *context)
 
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).
 
void dataStore (std::ostream &stream, SubAppBackups &backups, void *context)
 
void dataLoad (std::istream &stream, SubAppBackups &backups, void *context)
 

Function Documentation

◆ dataLoad() [1/2]

template<>
void dataLoad ( std::istream &  stream,
LocalRankConfig &  v,
void *  context 
)
inline

Definition at line 91 of file MultiApp.h.

92{
93 dataLoad(stream, v.num_local_sims, context);
94 dataLoad(stream, v.first_local_sim_index, context);
95 dataLoad(stream, v.num_local_apps, context);
96 dataLoad(stream, v.first_local_app_index, context);
97 dataLoad(stream, v.is_first_local_rank, context);
98 dataLoad(stream, v.my_first_rank, context);
99}
void dataLoad(std::istream &stream, LocalRankConfig &v, void *context)
Definition MultiApp.h:91
dof_id_type num_local_sims
The number of simulations that should/will be run locally on this rank.
Definition MultiApp.h:49
dof_id_type first_local_sim_index
The (global) index of the first local simulation for this rank.
Definition MultiApp.h:53
processor_id_type my_first_rank
For every rank working on a subapp, we store the first rank on each process to make the communication...
Definition MultiApp.h:74
bool is_first_local_rank
This is true if this rank is the primary/zero rank for a (sub)app slot.
Definition MultiApp.h:71
dof_id_type num_local_apps
The number of (sub)apps that should/will be run locally on this rank.
Definition MultiApp.h:58
dof_id_type first_local_app_index
The (global) index of the first local app for this rank.
Definition MultiApp.h:64

Referenced by dataLoad().

◆ dataLoad() [2/2]

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

Definition at line 1592 of file MultiApp.C.

1593{
1594 MultiApp * multi_app = static_cast<MultiApp *>(context);
1595 mooseAssert(multi_app, "Not set");
1596
1597 dataLoad(stream, cast_ref<std::vector<std::unique_ptr<Backup>> &>(backups), nullptr);
1598
1599 multi_app->restore();
1600}
void dataLoad(std::istream &stream, SubAppBackups &backups, void *context)
Definition MultiApp.C:1592
A MultiApp represents one or more MOOSE applications that are running simultaneously.
Definition MultiApp.h:140
virtual void restore(bool force=true)
Restore the state of every Sub App.
Definition MultiApp.C:806

Referenced by dataLoad().

◆ dataStore() [1/2]

template<>
void dataStore ( std::ostream &  stream,
LocalRankConfig &  v,
void *  context 
)
inline

Definition at line 79 of file MultiApp.h.

80{
81 dataStore(stream, v.num_local_sims, context);
82 dataStore(stream, v.first_local_sim_index, context);
83 dataStore(stream, v.num_local_apps, context);
84 dataStore(stream, v.first_local_app_index, context);
85 dataStore(stream, v.is_first_local_rank, context);
86 dataStore(stream, v.my_first_rank, context);
87}
void dataStore(std::ostream &stream, LocalRankConfig &v, void *context)
Definition MultiApp.h:79

Referenced by dataStore().

◆ dataStore() [2/2]

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

Definition at line 1581 of file MultiApp.C.

1582{
1583 MultiApp * multi_app = static_cast<MultiApp *>(context);
1584 mooseAssert(multi_app, "Not set");
1585
1586 multi_app->backup();
1587
1588 dataStore(stream, cast_ref<std::vector<std::unique_ptr<Backup>> &>(backups), nullptr);
1589}
void dataStore(std::ostream &stream, SubAppBackups &backups, void *context)
Definition MultiApp.C:1581
virtual void backup()
Save off the state of every Sub App.
Definition MultiApp.C:791

Referenced by dataStore().

◆ 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 1388 of file MultiApp.C.

1394{
1395 if (min_app_procs > nprocs)
1396 mooseError("minimum number of procs per app is higher than the available number of procs");
1397 else if (min_app_procs > max_app_procs)
1398 mooseError("minimum number of procs per app must be lower than the max procs per app");
1399
1400 mooseAssert(rank < nprocs, "rank must be smaller than the number of procs");
1401
1402 // A "slot" is a group of procs/ranks that are grouped together to run a
1403 // single (sub)app/sim in parallel.
1404
1405 const processor_id_type slot_size =
1406 std::max(std::min(cast_int<processor_id_type>(nprocs / napps), max_app_procs), min_app_procs);
1407 const processor_id_type nslots = std::min(
1408 nprocs / slot_size,
1409 cast_int<processor_id_type>(std::min(
1410 static_cast<dof_id_type>(std::numeric_limits<processor_id_type>::max()), napps)));
1411 mooseAssert(nprocs >= (nslots * slot_size),
1412 "Ensure that leftover procs is represented by an unsigned type");
1413 const processor_id_type leftover_procs = nprocs - nslots * slot_size;
1414 const dof_id_type apps_per_slot = napps / nslots;
1415 const dof_id_type leftover_apps = napps % nslots;
1416
1417 std::vector<int> slot_for_rank(nprocs);
1418 processor_id_type slot = 0;
1419 processor_id_type procs_in_slot = 0;
1420 for (processor_id_type rankiter = 0; rankiter <= rank; rankiter++)
1421 {
1422 if (slot < nslots)
1423 slot_for_rank[rankiter] = cast_int<int>(slot);
1424 else
1425 slot_for_rank[rankiter] = -1;
1426 procs_in_slot++;
1427 // this slot keeps growing until we reach slot size plus possibly an extra
1428 // proc if there were any leftover from the slotization of nprocs - this
1429 // must also make sure we don't go over max app procs.
1430 if (procs_in_slot == slot_size + 1 * (slot < leftover_procs && slot_size < max_app_procs))
1431 {
1432 procs_in_slot = 0;
1433 slot++;
1434 }
1435 }
1436
1437 if (slot_for_rank[rank] < 0)
1438 // ranks assigned a negative slot don't have any apps running on them.
1439 return {0, 0, 0, 0, false, 0};
1440 const processor_id_type slot_num = cast_int<processor_id_type>(slot_for_rank[rank]);
1441
1442 const bool is_first_local_rank = rank == 0 || (slot_for_rank[rank - 1] != slot_for_rank[rank]);
1443 const dof_id_type n_local_apps = apps_per_slot + 1 * (slot_num < leftover_apps);
1444
1445 processor_id_type my_first_rank = 0;
1446 for (processor_id_type rankiter = rank; rankiter > 0; rankiter--)
1447 if (slot_for_rank[rank] != slot_for_rank[rankiter])
1448 {
1449 my_first_rank = cast_int<processor_id_type>(slot_for_rank[rankiter + 1]);
1450 break;
1451 }
1452
1453 dof_id_type app_index = 0;
1454 for (processor_id_type slot = 0; slot < slot_num; slot++)
1455 {
1456 const dof_id_type num_slot_apps = apps_per_slot + 1 * (slot < leftover_apps);
1457 app_index += num_slot_apps;
1458 }
1459
1460 if (batch_mode)
1461 return {n_local_apps, app_index, 1, slot_num, is_first_local_rank, my_first_rank};
1462 return {n_local_apps, app_index, n_local_apps, app_index, is_first_local_rank, my_first_rank};
1463}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
uint8_t processor_id_type
uint8_t dof_id_type

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