Skip to main content

Run many jobs using MPI processes through a master/slave approach

Project description

# Mpijobs

A Python3 library for running many jobs on multiple processes, using
MPI.

## Example

The following example runs 3 jobs. For each of them, a message is
printed on the screen.

`````python
from mpi4py import MPI
from time import sleep

import mpijobs

class MyJob(mpijobs.Job):
def __init__(self,
params):
super().__init__()
self.params = params
self.result_str = None

def run(self, rank):
print("Hi, I am {0} (process {1})".format(self.params, rank))

# Pretend you're doing something useful
sleep(1.0)

# Perform a simple computation and save the result
self.result_str = self.params.upper()

JOB_LIST = [MyJob(name) for name in ('Bob', 'Alice', 'Stephen')]
RESULTS = mpijobs.run_event_loop(MPI.COMM_WORLD, JOB_LIST)

if MPI.COMM_WORLD.rank == 0: # Only one process should print the results
print("strings computed by the processes = [{0}]"
.format(', '.join([x.result_str for x in RESULTS])))
print("elapsed_time = [{0}]"
.format(', '.join([str(x.running_time) for x in RESULTS])))
`````

The program must be run using ``mpirun`` (or an equivalent program,
depending on your MPI library):

mpirun -n 3 python3 example.py

The output is the following (actual ranks and times might vary):

Hi, I am Stephen (process 2)
Hi, I am Alice (process 1)
Hi, I am Bob (process 1)
strings computed by the processes = [ALICE, STEPHEN, BOB]
elapsed_time = [0:00:01.001056, 0:00:01.001088, 0:00:01.001041]

## Copyright

See the COPYRIGHT.md file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpijobs-0.2.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

mpijobs-0.2.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file mpijobs-0.2.1.tar.gz.

File metadata

  • Download URL: mpijobs-0.2.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for mpijobs-0.2.1.tar.gz
Algorithm Hash digest
SHA256 640869d2609e9cca522a3ef3992e4266d42cff8cd3310cf3d8dd7ecaf70105c2
MD5 6756c8808dc6d6da5f6f4f1510c88b60
BLAKE2b-256 225fd0e8ef3a2915ff58c126199316d537db90dc42ec2a7d0bf14159a4e5cd00

See more details on using hashes here.

Provenance

File details

Details for the file mpijobs-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mpijobs-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe9fdfb21076e8bcfbba98258cfc9ccbd90a159a2794253835d68a0712ed6248
MD5 75b7207f45a81bb0c4416eb0a77cff9f
BLAKE2b-256 19612b2c9d6a16811cc997c414e2eea6f84a052daa2aa06f2ccec6c7ef0e845b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page