示例#1
0
		data=np.random.randint(0, 256, size=dataSize).astype(np.uint8)
		
		# How many times do we need to cycle send/receive for runtime=1s? 
		if total_time>0 and oldDataSize>0:
			# Calculate new repeats for 1 secons run
			repeats=int(repeats/total_time*2.0*oldDataSize/dataSize)
			if repeats==0:
				repeats=1
		else:
			# Initial repeats
			repeats=10000
		
		# Warm up
		for count in range(repeats):
			vm.sendMessage(taskID, data)
			dummy=vm.receiveMessage()
		
		# Time
		mark=time.time()
		for count in range(repeats):
			vm.sendMessage(taskID, data)
			dummy=vm.receiveMessage()
		total_time=time.time()-mark
		
		# Evaluate
		dt=total_time/2.0/repeats
		oldDataSize=dataSize
		tp=dataSize*8/dt
		
		# Print result
		print("Data size %9.3fkB, iterations=%6d, time=%7.0fus, speed=%5.3fMb/s" % (dataSize/1000.0, repeats, dt*1e6, tp/1e6))
示例#2
0
        data = np.random.randint(0, 256, size=dataSize).astype(np.uint8)

        # How many times do we need to cycle send/receive for runtime=1s?
        if total_time > 0 and oldDataSize > 0:
            # Calculate new repeats for 1 secons run
            repeats = int(repeats / total_time * 2.0 * oldDataSize / dataSize)
            if repeats == 0:
                repeats = 1
        else:
            # Initial repeats
            repeats = 10000

        # Warm up
        for count in range(repeats):
            vm.sendMessage(taskID, data)
            dummy = vm.receiveMessage()

        # Time
        mark = time.time()
        for count in range(repeats):
            vm.sendMessage(taskID, data)
            dummy = vm.receiveMessage()
        total_time = time.time() - mark

        # Evaluate
        dt = total_time / 2.0 / repeats
        oldDataSize = dataSize
        tp = dataSize * 8 / dt

        # Print result
        print(
示例#3
0
			taskIDList.extend(taskIDs)
			expr2taskID[expr]=taskIDs[0]
			taskCount+=1
			print("  Task ID: %s" % str(taskIDs[0]))
		else:
			taskIDList.append(None)
			print("  Not spawned")
	
	print 
	
	# Collect results from successfully spawned workers and wait for them to exit. 
	running=set(taskIDList)
	results={}
	while len(running)>0 and len(results)<taskCount:
		# Receive message, block
		recv=vm.receiveMessage(-1)
		# Process it
		if recv is not None and len(recv)==2:
			(srcID, msg)=recv
			# Process received result
			if type(msg) is MsgTaskExit:
				running.remove(srcID)
			elif type(msg) is MsgTaskResult:
				results[srcID]=msg.returnValue
	
	# Print results
	for ii in range(len(exprList)):
		expr=exprList[ii]
		taskID=taskIDList[ii]
		if taskID is not None:
			result=results[taskID]
示例#4
0
	print("Free slots: "+str(initialFreeSlots))
	
	# Spawn 2 tasks anywhere, send vm as argument with name 'vm'.  
	# The spawned function must be defined in an importable module outside main .py file. 
	print("\nSpawning 2 tasks, anywhere.")
	taskIDs=vm.spawnFunction(funclib.hello, kwargs={'vm': vm}, count=2)
	print("Spawned: ")
	for task in taskIDs:
		print "  ", str(task)
	print("Free slots: "+str(vm.freeSlots())+"\n")
	
	print("----\n"+vm.formatSpawnerConfig()+"----")
	
	# Blocking receive 4 messages (2 return values and 2 exit)
	while vm.freeSlots()!=initialFreeSlots:
		received=vm.receiveMessage()
		
		# Handle error (None) and timeout (empty tuple)
		if received is None or len(received)==0:
			continue
		
		# Unpack
		(fromId, msg)=received
		
		# Note that the received message may be comming from a dead worker. 
		# Verify that the message is comming from one of our workers. 
		if fromId not in taskIDs:
			continue
		
		# Handle message
		if type(msg) is MsgTaskResult:
示例#5
0
# Demonstrates file mirroring

import sys
from pyopus.parallel.mpi import MPI as VM
	
import funclib
import os

if __name__=='__main__':
	# Startup dir must contain funclib so we can import it on a worker 
	# (funclib is not in PYTHONPATH). 
	# Mirror current dir on spawner to workers local storage. 
	# Startupdir is by default the created local storage dir. 
	vm=VM(mirrorMap={'*':'.'}, debug=2)
	
	# Spawn 1 task anywhere, send vm as argument with name 'vm'.  
	# The spawned function must be defined in an importable module outside main .py file. 
	# Print some status information and local storage layout. 
	print("\nSpawning task.")
	taskIDs=vm.spawnFunction(funclib.helloLs, kwargs={'vm': vm}, count=1)
	print taskIDs
	print("Spawned: "+str(taskIDs[0]))
	print("Collecting stdout ...")
	
	# Wait for a message, e.g. TaskExit
	vm.receiveMessage()
	
	vm.finalize()
示例#6
0
    print("Free slots: " + str(initialFreeSlots))

    # Spawn 2 tasks anywhere, send vm as argument with name 'vm'.
    # The spawned function must be defined in an importable module outside main .py file.
    print("\nSpawning 2 tasks, anywhere.")
    taskIDs = vm.spawnFunction(funclib.hello, kwargs={'vm': vm}, count=2)
    print("Spawned: ")
    for task in taskIDs:
        print "  ", str(task)
    print("Free slots: " + str(vm.freeSlots()) + "\n")

    print("----\n" + vm.formatSpawnerConfig() + "----")

    # Blocking receive 4 messages (2 return values and 2 exit)
    while vm.freeSlots() != initialFreeSlots:
        received = vm.receiveMessage()

        # Handle error (None) and timeout (empty tuple)
        if received is None or len(received) == 0:
            continue

        # Unpack
        (fromId, msg) = received

        # Note that the received message may be comming from a dead worker.
        # Verify that the message is comming from one of our workers.
        if fromId not in taskIDs:
            continue

        # Handle message
        if type(msg) is MsgTaskResult: