A C-MPI parallel program that based on a MxN cartesian topology of tasks, each one sums its elements and sends its result to its neighbor (based on the picture below), until task 0 figures out the total sum of all elements.
Steps:
- calculating local sum for each task
- sending local results to the north neighbor
- summing total each column sum by the tasks at the top row
- sending local results of top row tasks to the west neighbor
- task 0 calculating the total sum
Limitations:
- the total number of the elements should be divisible by the number of tasks
- only the MPI_Cart_sub() function used
Guide to compile and run:
- download the .tar file from here: ftp://ftp.mcs.anl.gov/pub/mpi/old/mpich-1.2.4.tar.gz
- sudo apt-get install gcc
- sudo apt-get install libmpich2-dev
- mpicc -o cart_test cart_test.c
- mpiexec -n "number_of_tasks" ./cart_test
Tested on Lubuntu 12.04 (Precise Pangolin) on a virtual machine.