I'm having issues with using mpi4py, I'm attempting to make calculations such as a Fibonacci sequence, counting digits of Pi and finding prime numbers within a range; the main issue is I'm struggling to find a way to use MPI ranks in order to share the calculation load.
Some help would be greatly appreciated!
Fibbonachi code:
from mpi4py import MPI #Import the Python MPI module
import itertools as it #Import the intger module
import time #Import the process to measure how long the process takes
start_time = time.time() #Start the timer
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
number_of_fib = int(10000) #Number of sequences.
def fibonacci():
x,y = 0,1
while True:
yield x
y = x+y
yield y
x = x+y
for x in it.islice(fibonacci(), number_of_fib):
print x, (rank) #Print the result and which Pi calculated the result.
print "This process took", time.time() - start_time, "to finish" #Print how long the process took.