-
Notifications
You must be signed in to change notification settings - Fork 2
add-MPI-tutorial #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add-MPI-tutorial #63
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0e6b46
add-tutorial
eunmoliveira 975210a
Delete 2.scaling-with-mpi.md
eunmoliveira 5a511d9
add-tutorial-2
eunmoliveira b4ebc26
update-index
eunmoliveira 57d5e27
Update 2.scaling-with-mpi.md
eunmoliveira c27753a
Update 2.scaling-with-mpi.md
eunmoliveira a7364bc
Update 2.scaling-with-mpi.md
eunmoliveira e187c3e
Update 2.scaling-with-mpi.md
eunmoliveira 3de7d5a
Update 2.scaling-with-mpi.md
eunmoliveira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,134 @@ | ||
| --- | ||
| title: Scale gprMax with MPI | ||
| description: A step-by-step guide to running gprMax simulations with MPI | ||
| seo: | ||
| title: Scale gprMax simulations with MPI on Inductiva.AI | ||
| description: Step-by-step guide to running gprMax simulations with MPI on Inductiva.AI | ||
| --- | ||
|
|
||
| gprMax supports parallelism through **MPI** and **OpenMP**. For a deeper dive into how parallelism works in gprMax, refer to the [official documentation](https://docs.gprmax.com/en/latest/openmp_mpi.html). | ||
|
|
||
| In this tutorial, you will learn how to configure and run gprMax simulations sequentially and using MPI. We will use the `B-scan with a bowtie antenna model` from the gprMax example cases as our demonstration. | ||
|
|
||
| This example creates a B-scan using an antenna model. The setup includes a metal cylinder with a diameter of 20 mm buried in a dielectric half-space with a relative permittivity of 6. The simulation uses an antenna similar to the GSSI 1.5 GHz antenna. | ||
|
|
||
| For a B-scan, the antenna must be repositioned for each A-scan (trace). In this case, the B-scan covers a distance of 270 mm with traces every 5 mm, resulting in **54 separate model runs**. | ||
|
|
||
| ## Prerequisites | ||
| Download the required files [here](https://docs.gprmax.com/en/latest/examples_antennas.html#b-scan-with-a-bowtie-antenna-model) and save them to a folder named `b-scan-case`. | ||
|
|
||
| ## Sequential Processing | ||
| First, let's run the 54 models **sequentially**. This means the simulation will process the A-scans one after another: model 1, then model 2, and so on. | ||
|
|
||
| You can do this using the following command: | ||
|
|
||
| ``` | ||
| python -m gprMax cylinder_Bscan_GSSI_1500.in -n 54 | ||
| ``` | ||
|
|
||
| Here, `-n` specifies the number of runs. | ||
|
|
||
| Each run produces a separate output file. To merge them into a single result file, run: | ||
|
|
||
| ``` | ||
| python -m tools.outputfiles_merge cylinder_Bscan_GSSI_1500.in | ||
| ``` | ||
|
|
||
| The required Python script to run this case sequentially on Inductiva is shown below: | ||
|
|
||
| ```python | ||
| import inductiva | ||
|
|
||
| # Instantiate machine group | ||
| cloud_machine = inductiva.resources.MachineGroup( | ||
| machine_type="c2d-highcpu-16", | ||
| provider="GCP", | ||
| spot=True) | ||
|
|
||
| input_dir = "/Path/to/b-scan-case" | ||
|
|
||
| # Initialize the Simulator | ||
| gprmax = inductiva.simulators.GprMax(version="3.1.7") | ||
|
|
||
| commands_sequential = [ | ||
| "python -m gprMax cylinder_Bscan_GSSI_1500.in -n 54", | ||
| "python -m tools.outputfiles_merge cylinder_Bscan_GSSI_1500.in" | ||
| ] | ||
|
|
||
| # Start sequential simulation | ||
| task_sequential = gprmax.run(\ | ||
| input_dir=input_dir, | ||
| commands=commands_sequential, | ||
| on=cloud_machine, | ||
| n_vcpus=16) | ||
|
|
||
| # Wait for the simulations to finish | ||
| task_sequential.wait() | ||
| cloud_machine.terminate() | ||
| ``` | ||
|
|
||
| Running these 54 simulations sequentially took approximately **1 hour and 55 minutes**. | ||
|
|
||
| Next, we will explore MPI-based parallel execution, which will significantly speed up this case. | ||
|
|
||
| ## MPI Processing | ||
| gprMax supports MPI, allowing each of the 54 runs to be executed **in parallel**. This requires a machine with enough vCPUs to support all the runs. Hence, we'll be running the case on a `c2d-highcpu-112`, which has 112 vCPUs, providing ample resources for all 54 simulations to run concurrently. | ||
|
|
||
| > ⚠️ **Note on vCPUs and Hyperthreading**: In most cloud environments (e.g., Google Cloud), a vCPU represents a single thread rather than a full physical core. By default, Google Cloud VMs provide 2 vCPUs per physical core, so a `c2d-standard-112` machine with 112 vCPUs typically has 56 physical cores with hyperthreading enabled. | ||
|
|
||
| Wrap the Python command with `mpirun` as follows: | ||
|
|
||
| ``` | ||
| mpirun -n 55 python -m gprMax cylinder_Bscan_GSSI_1500.in -n 54 --mpi-no-spawn | ||
| ``` | ||
|
|
||
| - `-n 55` specifies the number of processes, which should be one more than the number of runs (`-n 54 + 1`) to account for the master process | ||
| - `--mpi-no-spawn` is recommended according to the [gprMax documentation](https://docs.gprmax.com/en/latest/openmp_mpi.html#mpi) | ||
|
|
||
| Here’s the Python script to run the case with MPI: | ||
|
|
||
| ```python | ||
| import inductiva | ||
|
|
||
| # Instantiate machine group | ||
| cloud_machine = inductiva.resources.MachineGroup( | ||
| machine_type="c2d-highcpu-112", | ||
| provider="GCP", | ||
| spot=True) | ||
|
|
||
| input_dir = "/Path/to/b-scan-case" | ||
|
|
||
| # Initialize the Simulator | ||
| gprmax = inductiva.simulators.GprMax(version="3.1.7") | ||
|
|
||
| commands_mpi = [ | ||
| "mpirun -n 55 python -m gprMax cylinder_Bscan_GSSI_1500.in -n 54 --mpi-no-spawn", | ||
| "python -m tools.outputfiles_merge cylinder_Bscan_GSSI_1500.in" | ||
| ] | ||
|
|
||
| # Start MPI simulation | ||
| task_mpi = gprmax.run(\ | ||
| input_dir=input_dir, | ||
| commands=commands_mpi, | ||
| on=cloud_machine, | ||
| n_vcpus=112) | ||
|
|
||
| # Wait for the simulations to finish | ||
| task_mpi.wait() | ||
| cloud_machine.terminate() | ||
| ``` | ||
|
|
||
| This MPI-based simulation significantly reduces the runtime compared to sequential execution, taking approximately **23 minutes**. | ||
|
|
||
| ## Results | ||
| The following table summarizes the performance and cost of sequential versus MPI-based execution for the `B-scan with a bowtie antenna model` case on Inductiva: | ||
|
|
||
| | Processing Type | Machine Type | Total Time | Estimated Cost (USD) | | ||
| |-----------------|-------------------|--------------|----------------------| | ||
| | Sequential | c2d-highcpu-16 | 1h, 55 min | 0.15 | | ||
| | MPI | c2d-highcpu-112 | 23 min | 0.21 | | ||
|
|
||
| Running the simulations on **Inductiva** using MPI-based parallel execution drastically reduces the runtime compared to sequential processing, from nearly **2 hours down to under 25 minutes**. Although the estimated cost for the larger machine is slightly higher, the time savings are significant, making MPI a highly efficient option for large-scale gprMax simulations. | ||
|
|
||
| ::docsbannersmall | ||
| :: | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Results missing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still waiting for the task to finish