How to use get_num_procs method in lisa

Best Python code snippet using lisa_python

mpi_util.py

Source:mpi_util.py Github

copy

Full Screen

1import numpy as np2from mpi4py import MPI3ROOT_PROC_RANK = 04def get_num_procs():5 return MPI.COMM_WORLD.Get_size()6def get_proc_rank():7 return MPI.COMM_WORLD.Get_rank()8def is_root_proc():9 rank = get_proc_rank()10 return rank == ROOT_PROC_RANK11def bcast(x):12 MPI.COMM_WORLD.Bcast(x, root=ROOT_PROC_RANK)13 return14def reduce_sum(x):15 return reduce_all(x, MPI.SUM)16def reduce_prod(x):17 return reduce_all(x, MPI.PROD)18def reduce_avg(x):19 buffer = reduce_sum(x)20 buffer /= get_num_procs()21 return buffer22def reduce_min(x):23 return reduce_all(x, MPI.MIN)24def reduce_max(x):25 return reduce_all(x, MPI.MAX)26def reduce_all(x, op):27 is_array = isinstance(x, np.ndarray)28 x_buf = x if is_array else np.array([x])29 buffer = np.zeros_like(x_buf)30 MPI.COMM_WORLD.Allreduce(x_buf, buffer, op=op)31 buffer = buffer if is_array else buffer[0]32 return buffer33def gather_all(x):34 is_array = isinstance(x, np.ndarray)35 x_buf = np.array([x])36 buffer = np.zeros_like(x_buf)37 buffer = np.repeat(buffer, get_num_procs(), axis=0)38 MPI.COMM_WORLD.Allgather(x_buf, buffer)39 buffer = list(buffer)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful