Last active
          June 28, 2018 09:18 
        
      - 
      
 - 
        
Save masa16/1cebf60495942f8dcfb152ef927f8d6d to your computer and use it in GitHub Desktop.  
    Pool のワーカー毎に gfarm2fs でマウントするための関数置き換え
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env python | |
| # mpiexec -n <number_of_nodes> /path/to/demo_gfarm_pool.py" | |
| from lsst.daf.persistence import LogicalLocation | |
| from hsc.pipe.base.pool import startPool, Pool, PoolSlave | |
| import gfarm2fs | |
| # invoke gfarm2fs on workers | |
| def init_gfarm(self, *args, **kwargs): | |
| super(PoolSlave, self).__init__(*args, **kwargs) | |
| gfarm2fs.open() | |
| PoolSlave.__init__ = init_gfarm | |
| # prepend gfarm mountpoint to file path | |
| oldLocString = LogicalLocation.locString | |
| def newLocString(self): | |
| return gfarm2fs.mountpoint + oldLocString(self) | |
| LogicalLocation.locString = newLocString | |
| # function to run on workers | |
| def test1(cache, data, *args, **kwargs): | |
| repo = LogicalLocation("/repo").locString() | |
| print("data = {} dir = {}".format(data,repo)) | |
| return data**2 | |
| startPool() | |
| pool1 = Pool(1) | |
| dataList = map(float, range(5)) | |
| print pool1.map(test1, dataList) | |
| Pool().exit() | |
| # $ mpiexec -n 4 $PWD/demo_gfarm_pool.py | |
| # data = 1.0 dir = /tmp/gfarm_masa_18622_000/repo | |
| # data = 2.0 dir = /tmp/gfarm_masa_18623_000/repo | |
| # data = 0.0 dir = /tmp/gfarm_masa_18621_000/repo | |
| # data = 4.0 dir = /tmp/gfarm_masa_18622_000/repo | |
| # data = 3.0 dir = /tmp/gfarm_masa_18621_000/repo | |
| # [0.0, 1.0, 4.0, 9.0, 16.0] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment