Parallel computing

This is a rather low science day.

I spent most of today understanding the mpi4py library.
To launch MC calculation on a multiple-threads machine, I would like to first scatter the indices for MC iteration to each thread.

With mpi4py this is what I do:

###### load necessary libraries #############
from mpi4py import MPI
from numpy import *

c = MPI.COMM_WORLD
### prepare to assign obsids to each node
nloop = 8
allloop = range(nloop)
crank = c.Get_rank()
csize = c.Get_size()

### ------------------------------------------------
### this chunk scatters [allloop] to each thread as [loop]
loop = []
for i in range(len(allloop)):
if mod(allloop[i], csize) == crank:
loop.append(allloop[i])
### ------------------------------------------------

### MC_calcul.py uses elements in the loop to decide
### which MC calculation it should execute.
execfile('MC_calcul.py')

Leave a Reply

Your email address will not be published. Required fields are marked *