Skip to content

remove note mpi tasks in sample_list

Jakob Roth requested to merge sample_list_mpi_load into NIFTy_8

In the Sample List documentation, we have a note that a sample list has to be loaded with the sample number of MPI tasks with which the Sample List was saved. Actually, this condition is not necessary. The number of MPI tasks does neither affect the order in which the samples are stored nor the order in which the samples are loaded again. To convince yourself, here are two code snippets:

Save a sample list:

import nifty8 as ift

from mpi4py import MPI
comm = MPI.COMM_WORLD
n_tasks = comm.Get_size()
my_rank = comm.Get_rank()
master = my_rank == 0

n_samples = 5

sp = ift.RGSpace(1)
mean = ift.full(sp, 0)

# create samples with "value of sample=index in list"
# create samples mpi parallel according to nifty convention
loc_inds = ift.utilities.shareRange(n_samples, n_tasks, my_rank)
smps = [ift.full(sp, ii) for ii in range(*loc_inds)]
neg = [False for _ in range(*loc_inds)]
samples = ift.ResidualSampleList(mean, smps, neg, comm)


samples.save('smp')
if master:
    print(f'saved sample list with {n_samples} samples distributed on {n_tasks} tasks')

Read the sample list and verify the number of samples and their order:

import nifty8 as ift

from mpi4py import MPI
comm = MPI.COMM_WORLD
n_tasks = comm.Get_size()
my_rank = comm.Get_rank()
master = my_rank == 0

samples = ift.ResidualSampleList.load('smp', comm)
n_samples = samples.n_samples

# check order of samples
for ii, smp in enumerate(samples.iterator()):
    assert(ii == smp.val[0])

if master:
    print(f'read sample list with {n_samples} samples, and distribute on {n_tasks} tasks')
    print('verified order of samples')

Thanks for noticing this Maximilian!

Merge request reports