Skip to content

Instantly share code, notes, and snippets.

@philippstroehle
Created November 7, 2013 21:20
Show Gist options
  • Save philippstroehle/7362037 to your computer and use it in GitHub Desktop.
Save philippstroehle/7362037 to your computer and use it in GitHub Desktop.
command line parsing in python, useful for parallelizing stuff on multicore machines
import argparse
def main(c=1, C=1):
for iteration in [iteration for iteration in range(config.iterations) if iteration % C == c - 1]:
logger.info("This is iteration %s" % iteration)
seed(iteration)
np.random.seed(iteration)
pass
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--core", type=int, help="id of the core to use", default=1)
parser.add_argument("-C", "--cores", type=int, help="total number of cores in use", default=1)
args = parser.parse_args()
main(c=args.core, C=args.cores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment