Many jobs in parallel

#!/usr/bin/env plams
import multiprocessing

# Run as many job simultaneously as there are cpu on the system:
maxjobs = multiprocessing.cpu_count()
print("Running up to {} jobs in parallel simultaneously".format(maxjobs))

# Set the default jobrunner to be parallel:
config.default_jobrunner = JobRunner(parallel=True, maxjobs=maxjobs)

# Number of cores for each job:
config.job.runscript.nproc = 1

# Load all molecules in the folder 'molecules':
molecules = read_molecules("molecules")

settings = Settings()
settings.input.ams.Task = "GeometryOptimization"
settings.input.dftb.Model = "GFN1-xTB"

results = []
for name, molecule in sorted(molecules.items()):
    job = AMSJob(molecule=molecule, settings=settings, name=name)
    results.append(job.run())

# Only print the results of the succesful caluclations:
for result in [r for r in results if r.ok()]:
    print("Energy for {:<12}: {:>10.3f} kcal/mol".format(result.name, result.get_energy(unit="kcal/mol")))

Note

To execute this PLAMS script:

Output

[09:42:34] PLAMS working folder: /scratch/rundir.plams.ManyJobsInParallel/plams_workdir
Running up to 8 jobs in parallel simultaneously
[09:42:34] JOB Acetic_acid STARTED
[09:42:34] JOB Benzene STARTED
[09:42:34] JOB Acetic_acid RUNNING
[09:42:34] JOB Butane STARTED
[09:42:34] JOB Ethane STARTED
[09:42:34] JOB Benzene RUNNING
...
...
[09:42:35] JOB Butane FINISHED
[09:42:35] JOB Butane SUCCESSFUL
[09:42:35] JOB Benzene FINISHED
[09:42:35] JOB Benzene SUCCESSFUL
Energy for Acetic_acid :  -9913.297 kcal/mol
Energy for Benzene     : -12039.485 kcal/mol
Energy for Butane      :  -8699.182 kcal/mol
Energy for Ethane      :  -4686.355 kcal/mol
Energy for Ethanol     :  -7629.287 kcal/mol
Energy for Formic_acid :  -7890.662 kcal/mol
Energy for Methanol    :  -5621.724 kcal/mol
Energy for Water       :  -3618.401 kcal/mol
[09:42:35] PLAMS run finished. Goodbye
Test duration in seconds: 1