Search code examples
cforkfibonaccimultiprocess

Calculate the fibonacci numbers in multiprocess way?


I am writing multi process fibonacci number calculator , I have a file that keeps track of the fibonacci numbers , first process open the file and write first fibonacci numbers (0 and 1 ), then do fork and its child process read the last two numbers add them up and write the next into file and close the file and fork again this process continue like that with forking and child adding up numbers and writing calculated number into file, using fork inside the for not a good solution neither recursive call,is there any suggesstion for problem ??

Here is the link of the problem we are talking about multi-process part of the problem which is part 2

http://cse.yeditepe.edu.tr/~sbaydere/fall2010/cse331/files/assignments/F10A1.pdf


Solution

  • Assuming you're calculating them in a "simple" way (i.e. without using a cunning formula), I don't think it's a good candidate for parallel processing at all.

    It's easy to come up with an O(n) solution, but each result depends on the previous one, so it's inherently tricky to parallelize. I can't see any benefit in your current parallel approach, as after each process has finished its own job and forked a child to get the next number, it's basically done... so you might as well do the work of the forked child in the existing process.