0

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.
Orsus
  • 1
  • 1
  • Can you post your code? Also, please read [How-to-Ask](https://stackoverflow.com/help/how-to-ask). – thewaywewere Apr 20 '17 at 00:38
  • Added the code to the post; sorry for my terrible ask, I'll keep it in mind for the future! – Orsus Apr 20 '17 at 00:52
  • Possible duplicate of [Parallelize Fibonacci sequence generator](http://stackoverflow.com/questions/16464498/parallelize-fibonacci-sequence-generator) – Shibli Apr 20 '17 at 17:40
  • @Shibli the question is MPI specific, not a duplicate. – thewaywewere Apr 21 '17 at 18:25
  • @thewaywewere This is a design problem. The code has nothing to do with MPI except importing module. Once the asker decides on design and codes some MPI then it becomes MPI-specific. – Shibli Apr 21 '17 at 20:29

0 Answers0