# it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt for more details. import simx from Person import * from HelloHandler import * random.seed(0) num_entities = 32 end_time = 1000000 # initialize simx.init("helloworldv2") simx.set_end_time(end_time) simx.set_min_delay(1) simx.init_env() # create Persons for i in xrange(num_entities): simx.create_entity(('p', i), Person) # create a message generation process class MessageGen(simx.Process): """ Schedule simple message sending and receiving """ def run(self): for evt_time in xrange(1, end_time / 2 - 1): hello_rcvr = ('p', random.choice(xrange(num_entities)))
def run(self): while(simx.get_now() < end_time): plt.clf() nx.draw_networkx_edges(G,Gpos,nodelist=[ncenter],alpha=0.4,edge_color='grey') nx.draw_networkx_nodes(G,Gpos,node_size=80,nodelist=p.keys(),node_color=p.values(),cmap=plt.cm.Reds_r) plt.xlim(-0.05,1.05) plt.ylim(-0.05,1.05) plt.axis('off') plt.draw() self.sleep(update_interval) simx.init("consensus") simx.set_end_time(end_time) simx.set_min_delay(min_delay) #simx.set_log_level("debug3") simx.init_env() for i in xrange(num_nodes): simx.create_entity(('n',i),Node,ent_data=({'gnode_id':i})) node_list.append(simx.get_entity(('n',i))) #quit() simx.get_controller().install_service(Receiver,eAddr_RECVR) simx.schedule_process(Updater()) #only rank 0 does the plotting if plot == True: import matplotlib.pyplot as plt
bp = self.os.create_process(BarProcess) # waits for Bar process to finish before resuming self.waitfor(bp) print "Foo process ",id(self)," on node",self.os.get_entity_id(), \ "returned from waitfor. Acquired resource ",self.resource, \ " at time ", simx.get_now() #initialize simx.init("ossim") simx.set_end_time(1000) simx.set_min_delay(1) simx.set_log_level("debug3") simx.init_env() num_nodes = 1 #create nodes for i in xrange(num_nodes): simx.create_entity(('n',i), os.Node,ent_data=({'num_cores':1})) num_processes = 1 #on each node create foo processes for i in xrange(num_nodes): node = simx.get_entity(('n',i)) # the node might not live in this memory space # in a distributed memory simulation
import simx from Person import * from HelloHandler import * ####### Initialize MPI and configuration framework####### simx.init("HelloWorld") end_time = 2**10 ##### set simulation configuration values ######## simx.set_min_delay(10) simx.set_end_time(end_time) # These are optional simx.set_output_file("helloworld.out") simx.set_log_level("info") simx.set_log_file("helloworld.log") ####### Initialize environment (logging, output etc) ########### simx.init_env() ##### Add services to be used in the simulation ######## # the second argument is a profile (should be dictionary (can be empty) or None) hh = simx.add_service('HelloHandlerPerson',None,[])
nx.draw_networkx_nodes(G, Gpos, node_size=80, nodelist=p.keys(), node_color=p.values(), cmap=plt.cm.Reds_r) plt.xlim(-0.05, 1.05) plt.ylim(-0.05, 1.05) plt.axis('off') plt.draw() self.sleep(update_interval) simx.init("consensus") simx.set_end_time(end_time) simx.set_min_delay(min_delay) #simx.set_log_level("debug3") simx.init_env() for i in xrange(num_nodes): simx.create_entity(('n', i), Node, ent_data=({'gnode_id': i})) node_list.append(simx.get_entity(('n', i))) #quit() simx.get_controller().install_service(Receiver, eAddr_RECVR) simx.schedule_process(Updater()) #only rank 0 does the plotting if plot == True: import matplotlib.pyplot as plt
# Free Software Foundation. Accordingly, this library is distributed in the hope that # it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt for more details. import simx from Person import * from HelloHandler import * ####### Initialize MPI and configuration framework####### simx.init("HelloWorld") end_time = 2**10 ##### set simulation configuration values ######## simx.set_min_delay(10) simx.set_end_time(end_time) # These are optional simx.set_output_file("helloworld.out") simx.set_log_level("info") simx.set_log_file("helloworld.log") ####### Initialize environment (logging, output etc) ########### simx.init_env() ##### Add services to be used in the simulation ######## # the second argument is a profile (should be dictionary (can be empty) or None) hh = simx.add_service('HelloHandlerPerson', None, []) ##### Create Entities ##########