Esempio n. 1
0
    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')
Esempio n. 2
0
runAlg = tuning_setups.batchOpenMPI_wrapper(tuning_setups.PSO_batch,
                                            tuning_setups.prob_ID)

tuningOpt = tMOPSO(
    optAlg=runAlg,
    CPV_lb=tuning_setups.PSO_CPV_lb,
    CPV_ub=tuning_setups.PSO_CPV_ub,
    CPV_validity_checks=tuning_setups.PSO_CPV_validity_checks,
    OFE_budgets=tuning_setups.PSO_OFE_budgets,
    sampleSizes=tuning_setups.PSO_sampleSizes,  #resampling size of 25
    resampling_interruption_confidence=tuning_setups.PSO_alpha,
    gammaBudget=tuning_setups.PSO_gammaBudget,  #tuning budget
    addtoBatch=runAlg.addtoBatch,
    processBatch=batchOpenMPI.processBatch)

batchOpenMPI.end_MPI_loop(print_stats=True)  #release workers, and print stats

print(tuningOpt)

OFE_budgets = [d.fv[0] for d in tuningOpt.PFA.designs]
Fmin_values = [d.fv[1] for d in tuningOpt.PFA.designs]

log_OFE_budgets = [d.xv[0] for d in tuningOpt.PFA.designs]
N_values = [int(d.xv[1]) for d in tuningOpt.PFA.designs]
w_values = [d.xv[2] for d in tuningOpt.PFA.designs]
c_p_values = [d.xv[3] for d in tuningOpt.PFA.designs]
c_g_values = [d.xv[4] for d in tuningOpt.PFA.designs]

plotlib.plot_PSO_results(OFE_budgets, Fmin_values, N_values, w_values,
                         c_p_values, c_g_values)
Esempio n. 3
0
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,True)
h = batchOpenMPI.batchFunction(h_org)

batchOpenMPI.begin_MPI_loop() 
# building processing que
print(f.addtoBatch(g.addtoBatch(3)))
print(h.addtoBatch(g.addtoBatch(3)))
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)

print('** nothing should be solved on the masters')
Esempio n. 4
0
"""
 example of how2use batchOpenMPI,
 simple example
"""

import batchOpenMPI
def f_inv_org(x) : 
    "function returns the inverse of a number"
    return 1.0/x
f_inv = batchOpenMPI.batchFunction(f_inv_org, permissible_exceptions = [ZeroDivisionError]) #creating function wrapper

batchOpenMPI.begin_MPI_loop() # both the workers and the master process run the same code up until here
print('this example script prints in the inverse of the integers from 0 to 9')
no = range(10) # creates [0,1,2,3,4,5,6,7,8,9]
for i in no :# adding all f_inv input and queing them for parallel processing
    f_inv.addtoBatch(i)
batchOpenMPI.processBatch() #get the workers to calculate all the inputs
res = [] #used for storing results
for i in no :
    try :
        res.append(f_inv(i))
    except ZeroDivisionError :
        print("couldn't inverse " + str(i) + " due to 0 division error") 
print(res)

batchOpenMPI.end_MPI_loop(print_stats=True) #release workers, and print stats