Skip to content

Commit

Permalink
Filling out the control options for number of threads and amount of m…
Browse files Browse the repository at this point in the history
…emory.
  • Loading branch information
paulsaxe committed Jul 24, 2020
1 parent 35ee949 commit 20bdd6f
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions psi4_step/psi4.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,28 @@ def __init__(
help='The amount of memory to use for Psi4'
)

self.parser.add_argument(
'--psi4-memory-factor',
default='90%',
help=(
'The amount of possible memory to use, typically about 90% to '
'allow for Psi4 not keeping track of all the memory used.'
)
)

# General options from seamm.ini on max cores and memory
self.parser.add_argument(
'--max-cores',
default='unlimited',
help='The maximum number of cores/threads to use in any step.'
)

self.parser.add_argument(
'--max-memory',
default='available',
help='The maximum amount of memory to use in any step.'
)

self.options, self.unknown = self.parser.parse_known_args()

# Set the logging level for this module if requested
Expand Down Expand Up @@ -297,13 +319,23 @@ def run(self):
if n_threads < 1:
n_threads = 1
if o.psi4_max_threads != 'default':
if n_threads > o.psi4_max_threads:
n_threads = o.psi4_max_threads
if n_threads > int(o.psi4_max_threads):
n_threads = int(o.psi4_max_threads)
if o.max_cores != "unlimited":
if n_threads > int(o.max_cores):
n_threads = int(o.max_cores)
logger.info(f'Psi4 will use {n_threads} threads.')

# How much memory to use
if '%' in o.psi4_memory_factor:
factor = float(o.psi4_memory_factor.rstrip('%')) / 100.0
else:
factor = float(o.psi4_memory_factor)
svmem = psutil.virtual_memory()
available = svmem.available * 0.9 # Safety factor....
if o.max_memory == 'all':
available = svmem.total * factor
else:
available = svmem.available * factor
if o.psi4_memory == 'default':
memory = available * (n_threads / n_cores)
else:
Expand All @@ -312,6 +344,9 @@ def run(self):
max_memory = dehumanize(o.psi4_max_memory)
if memory > max_memory:
memory = max_memory
if o.max_memory != 'all' and o.max_memory != 'available':
if memory > dehumanize(o.max_memory):
memory = dehumanize(o.max_memory)
# Psi applies a minimum of 250 MiB
min_memory = dehumanize('250 MiB')
if min_memory > memory:
Expand Down

0 comments on commit 20bdd6f

Please sign in to comment.