Site icon Tutor Bin

University of California Irvine MPI Based C Program Project

University of California Irvine MPI Based C Program Project

Description

For this assignment, you start from scratch. You may want to copy and use some code and makefile from previous assignments. Included is the previous reference code and MPI lecture notes.

Create two deliverables:

-Cyclicpassing.c

-Makefile (this should have a target to compile your program into an MPI executable named main.out

In the file cyclicPassing.c, write an MPI-based C program in which each rank does the following:

Create an int array of length 10 (call it outv).

oThe first 5 entries should be rank.

oThe last 5 entries should be rank+10.

Create another int array of length 10 (call it inv). Its contents don’t matter because they will be overwritten in a moment.

Use MPI to exchange data with neighboring ranks as follows:

oSend the first 5 entries of outv to the rank of index rank-1.

oSend the last 5 entries of outv to the rank of index rank+1.

oReceive a message of length 5 from the rank of index rank-1. Store this array in the first 5 entries of inv.

oReceive a message of length 5 from the rank of index rank+1. Store this array in the last 5 entries of inv.

oThere are no ranks with index -1 or index size, so you should wrap around. The first rank (index 0) and the last rank (index size-1) should take the places of one another’s missing neighbor rank (see example).

Pause execution for 0.05*rank seconds.

oThis makes the higher-numbered ranks pause a little longer, which should ensure that the upcoming print statements appear in the expected order.

oYou can easily pause execution with the sleep function provided by #include <unistd.h>

Print the rank index and outv on one line.

Print the rank index and inv on another line.

oYou may format this output nicely for readability. For example, I put a blank line after each inv array line so the arrays of the same rank are visually grouped.

If you put your arrays on the heap, free the memory.

Test your code. You don’t need to prove that you tested it, but you should do it anyway.

Here is an output example if there are four ranks:

Here’s the same output with arrows highlighting the messages sent by rank 1 to ranks 0 and 2.

Here’s the same output again with arrows highlighting the wrap-around messages between ranks 0 and size-1 (3 in this case).

MPI API functions used

MPI_Init: sets up MPI threads so that they can communicate (man page (Links to an external site.))

MPI_Comm_rank: get the process id for the MPI rank calling this function (man page (Links to an external site.))

MPI_Comm_size: get the number of MPI processes (man page (Links to an external site.))

MPI_Finalize: always call this from all MPI ranks before finishing the program (man page (Links to an external site.))

Websites for different MPI implementations

MPICH: https://www.mpich.org (Links to an external site.)

MVAPICH: https://mvapich.cse.ohio-state.edu (Links to an external site.)

OpenMPI: https://mvapich.cse.ohio-state.edu (Links to an external site.)

MPI Tutorials

https://mpitutorial.com/tutorials/

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Exit mobile version