MPI Online Quiz, 3rd quarter

Download the shell practice quiz program, quizshell.c

Also see the answer form (.doc version)

Remember to try and run programs using the /tmp directory - Here's how

Write a parallel application for factorial(n)

  1. Enter a number in process 0, for example 8
  2. Each process finds the partial product of the factorial(n) - Example (for four processes), process 0 finds 1*2; process 1 finds 3*4; process 2 finds 5*6; and process 3 finds 7*8.
  3. Use MPI_Reduce and MPI_PROD to find the product of all of these partial products - Example, process 0 finds 2 * 12 * 30 * 56 = 40320
  4. Process 0 prints the result (40320).
  5. This example shell program uses a while loop that repeats until the user enters a 0
  6. More examples:
      Number = 4, numprocesses = 4 
        Rank 0: 1
        Rank 1: 2
        Rank 2: 3
        Rank 3: 4
    
        Rank 0, using MPI_Reduce and MPI_PROD, calculates: 1*2*3*4=24
    
      Number = 12, numprocesses = 4
        Rank 0: 1*2*3
        Rank 1: 4*5*6
        Rank 2: 7*8*9
        Rank 3: 10*11*12
    
        Rank 0, using MPI_Reduce and MPI_PROD, calculates: 6*120*504*1320=479001600
    
    In these examples, the number of processes divides evenly into n

  7. Extra - write a version in which numproc does not necessarily divide evenly into n

    Example of the extra version:

      Number = 10, numprocesses = 4
        Rank 0: 1*2*3
        Rank 1: 4*5*6
        Rank 2: 7*8*9
        Rank 3: 10
    
        Rank 0, using MPI_Reduce and MPI_PROD, calculates: 6*120*504*10=3628800
    
      Number = 11, numprocesses = 4
        Rank 0: 1*2*3
        Rank 1: 4*5*6
        Rank 2: 7*8*9
        Rank 3: 10*11
    
        Rank 0, using MPI_Reduce and MPI_PROD, calculates: 6*120*504*110=39916800
    
      Number = 9, numprocesses = 4
        Rank 0: 1*2
        Rank 1: 3*4
        Rank 2: 5*6
        Rank 3: 7*8*9
    
        Rank 0, using MPI_Reduce and MPI_PROD, calculates: 2*12*30*504=362880