def g_org(x) : return x + 1 def h_org(x) : return x - 0.2 # creating batch functions f = batchOpenMPI.batchFunction(f_org) g = batchOpenMPI.batchFunction(g_org) h = batchOpenMPI.batchFunction(h_org) batchOpenMPI.begin_MPI_loop() # building processing que bi = g.addtoBatch(3,2) print(f.addtoBatch(bi)) print(h.addtoBatch(bi)) batchOpenMPI.processBatch() #get the workers to calculate all the inputs # now actuall code print ( """ f(x) = x ** 2 g(x) = x + 1 h(x) = x - 0.2 f(g(3)) = %f h(g(3)) = %f """ ) % (f(g(3)), h(g(3))) batchOpenMPI.end_MPI_loop(print_stats=True) #releases workers print('** nothing should be solved on the masters')
""" example of how2use batchOpenMPI, with lastProcessBatch=True to avoid process being tied down unessarcyilly """ import batchOpenMPI, time def randomPause_base(pause) : time.sleep(pause) randomPause = batchOpenMPI.batchFunction(randomPause_base) batchOpenMPI.begin_MPI_loop() print('lastProcessBatch=True example/test') pauses = [1,3] for pause in pauses : randomPause.addtoBatch(pause) batchOpenMPI.processBatch(lastProcessBatch=True) for pause in pauses: randomPause(pause) batchOpenMPI.end_MPI_loop(print_stats=True) print('The first worker should have exited before the last worker, and spent less time processing')