Pastebin

Paste #6694: test_yt_parallel

< previous paste - next paste>

Pasted by Max

Download View as text

import numpy as np
import os, sys, glob
import yt
yt.enable_parallelism()

import logging
fmt = '[%(levelname)s] %(asctime)-8s %(message)s'
logging.basicConfig(level=logging.DEBUG,
                    format=fmt,
                    datefmt='%H:%M:%S')    
del fmt

def main():
    if len(sys.argv) < 2:
        logging.error("Too few parameters. ")
        logging.info("Usage: distribution.py `filelst`.")
        sys.exit(-1)

    if '*' in sys.argv[1]:
        fnlst = glob.glob(sys.argv[1])
    else:
        fnlst = sys.argv[1:]

    storage = {}
    for sto, cfn in yt.parallel_objects(fnlst, storage = storage):
        logging.info(">>>>  %s", cfn)

        sto.result_id = cfn
        sto.result = { 'dat' : np.random.random() }

        logging.info(">>>> Done computing distributions for %s", cfn)

    logging.info(">>> Done with loop.") # <-- never reaches this line!

    if yt.is_root():
        logging.info("Gathering all data.")
        for i, (fn, vals) in enumerate(sorted(storage.items())):
            if vals is None:
                continue
            print i, fn, vals


    logging.info("Done with all.")
    
if __name__ == '__main__':
    main()

    

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.