Skip to content
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

Adding section in parcels structure tutorial on optimisation and parallelisation #1555

Merged
merged 3 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions docs/examples/tutorial_parcels_structure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"2. [**ParticleSet**](#2.-ParticleSet). Define the type of particles. Also additional `Variables` can be added to the particles (e.g. temperature, to keep track of the temperature that particles experience).\n",
"3. [**Kernels**](#3.-Kernels). Define and compile kernels. Kernels perform some specific operation on the particles every time step (e.g. interpolate the temperature from the temperature field to the particle location).\n",
"4. [**Execution and output**](#4.-Execution-and-Output). Execute the simulation and write and store the output in a NetCDF file.\n",
"5. [**Optimising and parallelising**](#5.-Optimising-and-parallelising). Optimise and parallelise the code to run faster.\n",
"\n",
"We discuss each component in more detail below.\n",
"\n",
Expand Down Expand Up @@ -393,8 +394,6 @@
"source": [
"<div class=\"alert alert-info\">\n",
"\n",
"### A note on output chunking\n",
"\n",
"Note the use of the `chunks` argument in the `pset.ParticleFile()` above. This controls the 'chunking' of the output file, which is a way to optimize the writing of the output file. The default chunking for the output in Parcels is `(number of particles in initial particleset, 1)`. \n",
"Note that this default may not be very efficient if \n",
"1. you use `repeatdt` to release a relatively small number of particles _many_ times during the simulation and/or\n",
Expand Down Expand Up @@ -426,6 +425,55 @@
"\n",
"- [How the output is structured and how to start your own analysis](https://docs.oceanparcels.org/en/latest/examples/tutorial_output.html)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Optimising and parallelising"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On linux and macOS, Parcels can be run in parallel using MPI. This can be done by running the script with\n",
"```shell\n",
"mpirun -np <number of processors> python <scriptname>.py\n",
"``` \n",
"\n",
"The script will then run in parallel on the number of cores specified. Note that this is a fairly 'simple' implementation of paralelisation, where the number of particles is simply spread over the cores (using a `kdtree` for some optimisation). This means that the more cores you use, the less particles each core will have to handle, and the faster the simulation will run. However, the speedup is not linear, as each core will need to load its own `FieldSet`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### For more tutorials on MPI and parallelisation:\n",
"\n",
"- [Optimising the partitioning of the particles with a user-defined `partition_function`](https://docs.oceanparcels.org/en/latest/examples/documentation_MPI.html#Optimising-the-partitioning-of-the-particles-with-a-user-defined-partition_function)\n",
"- [Future developments: load balancing](https://docs.oceanparcels.org/en/latest/examples/documentation_MPI.html#Future-developments:-load-balancing)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Another good way to optimise Parcels and speed-up execution is to chunk the `FieldSet` with `dask`, using the `chunksize` argument in the `FieldSet` creation. This will allow Parcels to load the `FieldSet` in chunks. \n",
"\n",
"Using chunking can be especially useful when working with large datasets _and_ when the particles only occupy a small region of the domain.\n",
"\n",
"Note that the **default** is `chunksize=None`, which means that the `FieldSet` is loaded in its entirety. This is generally the most efficient way to load the `FieldSet` when the particles are spread out over the entire domain.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### For more tutorials chunking and dask:\n",
"\n",
"- [Chunking the FieldSet with dask](https://docs.oceanparcels.org/en/latest/examples/documentation_MPI.html#Chunking-the-FieldSet-with-dask)"
]
}
],
"metadata": {
Expand Down
Loading