update usage

This commit is contained in:
RvDijk
2017-12-18 14:40:21 +01:00
parent 2d0685c0d7
commit a8faca765d
24 changed files with 539 additions and 0 deletions

20
test_batch/python_cpu.py Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
import multiprocessing
import os # For reading the amount of CPUs requested.
import time # For clocking the calculation.
def double(data):
return data ** 2
if __name__ == '__main__':
begin = time.time()
inputs = list(range(10000)) # Makes an array from 0 to 10
poolSize = int(os.environ['SLURM_JOB_CPUS_PER_NODE']) # Amount of CPUs requested.
pool = multiprocessing.Pool(processes=poolSize,)
poolResults = pool.map(double, inputs) # Do the calculation.
pool.close() # Stop pool accordingly.
pool.join() # Wrap up data from the workers in the pool.
print ('Pool output:', poolResults) # Results.
elapsedTime = time.time() - begin
print ('Time elapsed for ' , poolSize, ' workers: ', elapsedTime, ' seconds')