コード例 #1
0
ファイル: pi.py プロジェクト: nesi/training
def Pi(num_steps):
	sum = 0
	start = time.time()

	# Call the function implemented in the C extention here
	sum = cpi.loop(num_steps)

	pi = sum/num_steps

	end = time.time()
	print "Pi with %d steps is %.20f in %f secs"\
	 %(num_steps,\
	 pi, end-start)
コード例 #2
0
ファイル: pi.py プロジェクト: nesi/training
def Pi(num_steps):
	comm = MPI.COMM_WORLD
	rank = comm.Get_rank()
	size = comm.Get_size()

	sum = 0
	start = time.time()

	# Call the function implemented in the C extention here
	num_steps2 = num_steps/size
	begin = num_steps2 * rank
	end = num_steps2 * (rank+1)
	local_sum = cpi.loop(num_steps,begin,end)

	sum = comm.reduce(local_sum, op=MPI.SUM, root=0)

	if rank == 0:

		end = time.time()
		pi = sum/num_steps
		print "Pi with %d steps is %.20f in %f secs"\
			 %(num_steps,\
			 pi, end-start)
コード例 #3
0
def Pi(num_steps):
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    sum = 0
    start = time.time()

    # Call the function implemented in the C extention here
    num_steps2 = num_steps / size
    begin = num_steps2 * rank
    end = num_steps2 * (rank + 1)
    local_sum = cpi.loop(num_steps, begin, end)

    sum = comm.reduce(local_sum, op=MPI.SUM, root=0)

    if rank == 0:

        end = time.time()
        pi = sum / num_steps
        print "Pi with %d steps is %.20f in %f secs"\
          %(num_steps,\
          pi, end-start)