Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

 

import multiprocessing 

from cosmoHammer.MpiCosmoHammerSampler import MpiCosmoHammerSampler 

 

 

class ConcurrentMpiCosmoHammerSampler(MpiCosmoHammerSampler): 

""" 

A sampler implementation extending the mpi sampler in order to allow to  

distribute the computation with MPI and using multiprocessing on a single node. 

 

:param threads: (optional) 

The number of threads to use for parallelization. If ``threads == 1``, 

then the ``multiprocessing`` module is not used but if 

``threads > 1``, then a ``Pool`` object is created 

 

:param kwargs: key word arguments passed to the CosmoHammerSampler 

 

""" 

def __init__(self, threads=1, **kwargs): 

""" 

CosmoHammer sampler implementation 

 

""" 

 

self.threads = threads 

 

super(ConcurrentMpiCosmoHammerSampler, self).__init__(**kwargs) 

 

 

def _getMapFunction(self): 

if self.threads > 1: 

pool = multiprocessing.Pool(self.threads) 

return pool.map 

else: 

return map