mpi_utils

_logic_true(args)[source]
mpi_parse(parser, comm, mpi_rank, options=None, args_logic_fnc=<function _logic_true>)[source]

Parse arguments on the master node, then broadcast.

Parameters:
  • parser (argparse.ArgumentParser) – Parser to be used.

  • comm (MPI.COMM_WORLD) – MPI comm object for bcast

  • mpi_rank (int) – Rank of the MPI process.

  • options (None or list, default: None) – Options to parse. None parses sys.argv

  • args_logic_fnc (Callable[[args], bool], default: True) – Logic function to check for args.

mpi_fnc_bcast(fnc, comm=None, mpi_rank=0, err_msg='', *args, **kwargs)[source]

Wrapper function to run function then broadcast. Return value of fnc must be broadcastable.

Example:

# Reading lines of integers
# from file `filename_for_integers` using np.loadtxt
import numpy as np

ints_in_file = mpi_fnc_bcast(
        np.loadtxt,
        comm, mpi_rank, "Error while reading file.",
        filename_for_integers, dtype=int)
Parameters:
  • fnc (callable) – Function to evaluate.

  • comm (MPI.COMM_WORLD or None, default: None) – MPI comm object for bcast

  • mpi_rank (int, default: 0) – Rank of the MPI process.

  • err_msg (str, default: '') – Error message to use raising QsonicException.

  • *args – Arguments such as fnc(3, 4).

  • **kwargs – Keyword arguments such as fnc(dtype=int)

Returns:

result – Function fnc(*args, **kwargs).

Return type:

fnc

Raises:

QsonicException – If any error occur while doing fnc.

balance_load(split_catalog, mpi_size)[source]

Load balancing function. The return value can be scattered.

Parameters:
  • split_catalog (list(ndarray)) – List of catalog. Each element is a ndarray with the same healpix.

  • mpi_size (int) – Number of MPI tasks running.

Returns:

local_queue – Spectra that ranks are reponsible for in split_catalog format.

Return type:

list(list(ndarray))

class MPISaver(fname, mpi_rank)[source]

Bases: object

A simple class to write to a FITS file on master node.

Parameters:
  • fname (str) – Filename. Does not create if empty string.

  • mpi_rank (int) – Rank of the MPI process. Creates FITS if 0.

close()[source]

Close FITS file.

write(data, names=None, extname=None, header=None)[source]

Write to FITS file.

Parameters:
  • data (list(ndarray)) – Data to write to extension.

  • names (list(str)or None, default: None) – Column names for data.

  • extname (str or None, default: None) – Extention name.

  • header (dict or None, default: None) – Header dictionary to save.