-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parallel processing with dask.distributed (#16)
Add command line arguments `--dask-distributed-local-core-fraction` and `--dask-distributed-local-memory-fraction` which can be used to enable multiprocessing by setting the former to a non-zero fraction representing the fraction of CPU cores on the local machine to use for parallel processing with `dask.distrubted.LocalCluster`. The latter argument set what fraction of the total system memory is allocated to the workers.
- Loading branch information
Showing
9 changed files
with
600 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,12 @@ jobs: | |
linting: | ||
name: "pre-commit hooks" | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
# don't use python3.12 because flake8 finds extra issues with that | ||
# version | ||
python-version: "3.11" | ||
- uses: pre-commit/[email protected] |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,20 +1,64 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
import psutil | ||
from dask.diagnostics import ProgressBar | ||
from dask.distributed import LocalCluster | ||
from loguru import logger | ||
|
||
from .create_dataset import create_dataset_zarr | ||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
) | ||
parser.add_argument("config", help="Path to the config file", type=Path) | ||
parser.add_argument( | ||
"--show-progress", help="Show progress bar", action="store_true" | ||
) | ||
parser.add_argument( | ||
"--dask-distributed-local-core-fraction", | ||
help="Fraction of cores to use on the local machine to do multiprocessing with dask.distributed", | ||
type=float, | ||
default=0.0, | ||
) | ||
parser.add_argument( | ||
"--dask-distributed-local-memory-fraction", | ||
help="Fraction of memory to use on the local machine (when doing multiprocessing with dask.distributed)", | ||
type=float, | ||
default=0.9, | ||
) | ||
args = parser.parse_args() | ||
|
||
if args.show_progress: | ||
ProgressBar().register() | ||
|
||
if args.dask_distributed_local_core_fraction > 0.0: | ||
# get the number of system cores | ||
n_system_cores = os.cpu_count() | ||
# compute the number of cores to use | ||
n_local_cores = int(args.dask_distributed_local_core_fraction * n_system_cores) | ||
# get the total system memory | ||
total_memory = psutil.virtual_memory().total | ||
# compute the memory per worker | ||
memory_per_worker = ( | ||
total_memory / n_local_cores * args.dask_distributed_local_memory_fraction | ||
) | ||
|
||
logger.info( | ||
f"Setting up dask.distributed.LocalCluster with {n_local_cores} cores and {memory_per_worker/1024/1024:0.0f} MB of memory per worker" | ||
) | ||
|
||
cluster = LocalCluster( | ||
n_workers=n_local_cores, | ||
threads_per_worker=1, | ||
memory_limit=memory_per_worker, | ||
) | ||
|
||
client = cluster.get_client() | ||
# print the dashboard link | ||
logger.info(f"Dashboard link: {cluster.dashboard_link}") | ||
|
||
create_dataset_zarr(fp_config=args.config) |
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.