-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10623 from rwcarlsen/split-mesh
implement convenience workflow for using distributed mesh
- Loading branch information
Showing
14 changed files
with
269 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
# Mesh Splitting | ||
|
||
MOOSE provides the ability to pre-split a mesh into several chunks for use with | ||
[distributed mesh](/Mesh/index.md#Replicated-and-Distributed-Mesh). | ||
This can be useful if the whole mesh is too big to fit into memory. A split-mesh | ||
workflow involves generating the mesh split configuration(s) and then telling moose | ||
to use them when you run simulations. This is described in the sections below. | ||
|
||
## Generating Split Configurations | ||
|
||
You can run MOOSE with the `--split-mesh <split1>[,<split2>]...` flag which takes a | ||
comma-separated list of describing each split with an integer number of chunks to split the mesh | ||
into. | ||
|
||
``` | ||
$ moose-app-opt -i your_input.i --split-mesh 13,42,1000 | ||
Splitting 13 ways... | ||
- writing 13 files per process... | ||
Splitting 42 ways... | ||
- writing 42 files per process... | ||
... | ||
``` | ||
|
||
This will create three split configurations for your mesh that include 13, 42, and 1000 chunks | ||
each. If your input file uses the mesh file `foo.e`, this process will generate a directory | ||
named `foo.cpr`. In general, you should neither rename this directory nor modify its | ||
contents. All split configurations for the mesh will be stored in this directory (even across | ||
independent splitting operations). | ||
|
||
For non-file-based mesh cases (e.g. GeneratedMesh), you will need to tell MOOSE what name to use | ||
for the split mesh files it will generate using the `--split-file <file_name>` flag; in general, | ||
you should use the `.cpr` file extension here. For example: | ||
|
||
``` | ||
$ moose-app-opt -i your_input.i --split-mesh 42 --split-file foo.cpr | ||
``` | ||
|
||
You can also run the splitting operation itself in parallel on several processors to speed up the | ||
operation: | ||
|
||
``` | ||
$ mpiexec -n 9 -i moose-app-opt your_input.i --split-mesh 42 | ||
Splitting 42 ways... | ||
- writing 5 files per process... | ||
``` | ||
|
||
This will generate the same split configuration as the 42 chunk split generated by the first | ||
command but just generates it in parallel. | ||
|
||
## Using Split Meshes | ||
|
||
To use a mesh split configuration use the `--use-split` flag (which takes no arguments): | ||
|
||
``` | ||
$ mpiexec -n 42 moose-app-opt your_input.i --use-split | ||
``` | ||
|
||
This will cause MOOSE to look for a mesh split configuration with 42 chunks. If one exists, MOOSE | ||
will use it running in a distributed mesh mode, otherwise an error will occur. Note that you do | ||
not need to modify your input file - MOOSE automatically switches to using the pre-split | ||
distributed mesh regardless of the mesh type specified in the input file. If your input file does | ||
not use a file-based mesh, you will need to specify a split mesh file name using the | ||
`--split-file <file_name>` flag just as you did when splitting the mesh: | ||
|
||
``` | ||
$ mpiexec -n 42 moose-app-opt your_input.i --use-split --split-file foo.cpr | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#ifndef SPLITMESHACTION_H | ||
#define SPLITMESHACTION_H | ||
|
||
#include "Action.h" | ||
|
||
#include <string> | ||
|
||
class SplitMeshAction; | ||
|
||
template <> | ||
InputParameters validParams<SplitMeshAction>(); | ||
|
||
class SplitMeshAction : public Action | ||
{ | ||
public: | ||
SplitMeshAction(InputParameters params); | ||
|
||
virtual void act() override; | ||
}; | ||
|
||
#endif // SPLITMESHACTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "SplitMeshAction.h" | ||
|
||
#include "MooseApp.h" | ||
#include "MooseUtils.h" | ||
#include "MooseMesh.h" | ||
#include "libmesh/checkpoint_io.h" | ||
|
||
template <> | ||
InputParameters | ||
validParams<SplitMeshAction>() | ||
{ | ||
return validParams<Action>(); | ||
} | ||
|
||
SplitMeshAction::SplitMeshAction(InputParameters params) : Action(params) {} | ||
|
||
void | ||
SplitMeshAction::act() | ||
{ | ||
auto mesh = _app.actionWarehouse().mesh(); | ||
|
||
if (mesh->getFileName() == "" && _app.parameters().get<std::string>("split_file") == "") | ||
mooseError("Output mesh file name must be specified (with --split-file) when splitting " | ||
"non-file-based meshes"); | ||
|
||
auto splitstr = _app.parameters().get<std::string>("split_mesh"); | ||
std::vector<unsigned int> splits; | ||
bool success = MooseUtils::tokenizeAndConvert(splitstr, splits, ", "); | ||
if (!success) | ||
mooseError("invalid argument for --split-mesh: '", splitstr, "'"); | ||
|
||
for (std::size_t i = 0; i < splits.size(); i++) | ||
{ | ||
processor_id_type n = splits[i]; | ||
Moose::out << "Splitting " << n << " ways..." << std::endl; | ||
|
||
auto cpr = libMesh::split_mesh(*mesh, n); | ||
Moose::out << " - writing " << cpr->current_processor_ids().size() << " files per process..." | ||
<< std::endl; | ||
cpr->binary() = true; | ||
auto fname = mesh->getFileName(); | ||
if (fname == "") | ||
fname = _app.parameters().get<std::string>("split_file"); | ||
fname = MooseUtils::stripExtension(fname) + ".cpr"; | ||
cpr->write(fname); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.