Changeset 150
- Timestamp:
- 06/26/09 20:32:23 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pyina/pyina/differential_evolution.py
r149 r150 32 32 33 33 """ 34 #FIXME: only master fcalls[0] checked vs maxfun; should be fcalls for all ranks35 #FIXME: for disp=1, master should print summary of fcalls; not each rank prints36 34 #FIXME: enable_signal_handler doesn't work. [Ctrl-C kills the solver] 37 35 #FIXME: make a module level variable MASTER=0 (?) [replaces master=0] … … 59 57 from pickle import loads, dumps 60 58 from pyina.parallel_map import parallel_map 61 from pyina._pyina import bcastString 59 from pyina._pyina import bcastString, sendString, receiveString 62 60 63 61 import mpiconsts … … 92 90 self.probability = 0.5 93 91 self.map = parallel_map 92 93 # MPI ######### 94 import mpi 95 size = mpi.world().size 96 ############### 97 self.functioncalls = [0] * size 94 98 95 99 def SetMapping(self, mapper): … … 169 173 world = mpi.world() 170 174 size = world.size 175 #comm = pyina._pyina.commDup(world.handle()) 171 176 ############### 172 177 … … 196 201 generation = 0 197 202 for generation in range(self._maxiter): 203 204 # MPI #####BEGIN: summing functioncalls 205 if world.rank == master: # MPI ######### 206 self.functioncalls[0] = fcalls[0] 207 for i in range(1,size): 208 (message,status) = receiveString(world.handle(), MPI_ANY_SOURCE, MPI_ANY_TAG) 209 sender,anstag = status['MPI_SOURCE'],status['MPI_TAG'] 210 self.functioncalls[sender] = loads(message) 211 else: 212 functioncalls = dumps(fcalls[0]) 213 sendString(world.handle(), master, world.rank, functioncalls) 214 # MPI #####END: summing functioncalls 215 198 216 if world.rank == master: # MPI ######### 199 217 StepMonitor(self.bestSolution[:], self.bestEnergy) 200 if fcalls[0] >= self._maxfun: 218 if sum(self.functioncalls) >= self._maxfun: 219 #if fcalls[0] >= self._maxfun: 201 220 nn = bcastString(world.handle(), master, "stop") # MPI ##### 202 221 break … … 263 282 warnflag = 0 264 283 265 if fcalls[0] >= self._maxfun: 284 if sum(self.functioncalls) >= self._maxfun: 285 #if fcalls[0] >= self._maxfun: 266 286 warnflag = 1 267 287 if disp and world.rank == master: # MPI ##### … … 278 298 print " Current function value: %f" % fval 279 299 print " Iterations: %d" % self.generations 280 print " Function evaluations: %d (Rank: %d)" % (fcalls[0],world.rank) 300 print " Function evaluations: %d" % sum(self.functioncalls) 301 #print " Function evaluations: %s" % self.functioncalls #XXX: print fcalls per node 281 302 282 303 return
Note: See TracChangeset
for help on using the changeset viewer.