Pointtopoint communication
Blocking communications
MPI2Send1°. An integer is given in each process. Send all given integers to the master process using the MPI_Send and MPI_Recv functions (the blocking functions for standard communication mode) and output received integers in the master process in ascending order of ranks of sending processes.
MPI2Send2°. A real number is given in each slave process. Send all given numbers to the master process using the MPI_Bsend (the blocking function for buffered send) and MPI_Recv functions and output received numbers in the master process in descending order of ranks of sending processes. Use the MPI_Buffer_attach function for attaching a buffer to a process.
MPI2Send3°. Four integers are given in each slave process. Send all given integers to the master process using one call of the MPI_Send function for each sending process. Output received integers in the master process in ascending order of ranks of sending processes.
MPI2Send4°. An integer N (0 < N < 5) and a sequence of N integers are given in each slave process. Send all given sequences to the master process using one call of the MPI_Bsend function for each sending process. Output received integers in the master process in ascending order of ranks of sending processes. Use the MPI_Get_count to determine the size of received sequences.
MPI2Send5°. A sequence of real numbers is given in the master process; the size of sequence is equal to the number of slave processes. Send each element of given sequence to corresponding slave process using the MPI_Send function: the first number should be sent to the process 1, the second number should be sent to the process 2, and so on. Output received numbers in the slave processes.
MPI2Send6°. A sequence of real numbers is given in the master process; the size of sequence is equal to the number of slave processes. Send each element of given sequence to corresponding slave process (in inverse order) using the MPI_Bsend function: the first number should be sent to the last process, the second number should be sent to the last but one process, and so on. Output received numbers in the slave processes.
MPI2Send7°. An integer N and a sequence of N real numbers is given in the master process; K − 1 ≤ N < 10, K is the number of processes. Send elements of given sequence with order number 1, 2, …, K − 2 to slave process of rank 1, 2, …, K − 2 respectively, and send remaining elements of the sequence to the process K − 1. Output received numbers in the slave processes. Use the MPI_Send function to send data, use the MPI_Get_count function to determine the size of received sequences in the process K − 1.
MPI2Send8°. An integer is given in each slave process; only one of given integers is nonzerovalued. Send nonzero integer to the master process. Output the received number and the rank of sending process in the master process. Use the MPI_Recv function with the MPI_ANY_SOURCE parameter to receive data in the master process.
MPI2Send9°. An integer N is given in each slave process; one of given integers is positive, others are zerovalued. Also a sequence of N real numbers is given in the slave process with nonzero integer N. Send the given sequence to the master process. Output the received numbers and the rank of sending process in the master process. Use the MPI_Recv function with the MPI_ANY_SOURCE parameter to receive data in the master process.
MPI2Send10°. An integer N is given in each slave process, an integer K (> 0) is given in the master process; the number K is equal to number of slave processes whose given integers N are positive. Send all positive integers N to the master process. Output sum of received numbers in the master process. Use the MPI_Recv function with the MPI_ANY_SOURCE parameter to receive data in the master process.
MPI2Send11°. A real number is given in each process. Send the given number from the master process to all slave processes and send the given numbers from the slave processes to the master process. Output the received numbers in each process. The numbers received by the master process should be output in ascending order of ranks of sending processes. Use the MPI_Ssend function to send data. Note. The MPI_Ssend function provides a synchronous data transfer mode, in which the operation of sending a message will be completed only after the receiving process starts to receive this message. In the case of data transfer in synchronous mode, there is a danger of deadlocks because of the incorrect order of the function calls for sending and receiving data.
MPI2Send12°. An integer is given in each process. Using the MPI_Ssend and MPI_Recv functions, perform the right cyclic shift of given data by step 1 (that is, the given integer should be sent from the process 0 to the process 1, from the process 1 to the process 2, …, from the last process to the process 0). Output the received number in each process. Note. See note to MPI2Send11.
MPI2Send13°. An integer is given in each process. Using the MPI_Ssend and MPI_Recv functions, perform the left cyclic shift of given data by step −1 (that is, the given integer should be sent from the process 1 to the process 0, from the process 2 to the process 1, …, from the process 0 to the last process). Output the received number in each process. Note. See note to MPI2Send11.
MPI2Send14°. Two integers are given in each process. Send the first integer to the previous process and the second integer to the next process (use the MPI_Ssend and MPI_Recv functions). The last process is assumed to be the previous one for the master process, the master process is assumed to be the next one for the last process. Output the received numbers in each process in the following order: the number received from the previous process, then the number received from the next process. Note. See note to MPI2Send11.
MPI2Send15°. A real number A and an integer N are given in each process; the set of given integers N contains all values in the range 0 to K − 1, K is the number of processes. Send the number A to the process N in each process (use the MPI_Send and MPI_Recv functions and the MPI_ANY_SOURCE parameter). Output the received number and the rank of sending process in each process. Note. If the value N equals the rank of the process in which it is given, then the required results can be output without calling the MPI functions. This is the only way for MPICH2 version 1.3, since, in this version, the MPI_Send function call is erroneous if the sending and receiving processes are the same.
MPI2Send16°. An integer N is given in each process; the value of N is equal to 1 for one process and is equal to 0 for others. Also a sequence of K − 1 real numbers is given in the process with nonzero integer N; K is the number of processes. Send each number from the given sequence to one of other processes in ascending order of ranks of receiving processes. Output the received number in each process.
MPI2Send17°. A sequence of K − 1 integers is given in each process; K is the number of processes. Send one of the integers from the given sequence in each process to the corresponding process in ascending order of ranks of receiving processes. Output the received numbers in each process in ascending order of ranks of sending processes.
MPI2Send18°. The number of processes is an even number. An integer N (0 < N < 5) and a sequence of N real numbers are given in each process. Exchange given sequences of processes 0 and 1, 2 and 3, and so on, using the MPI_Sendrecv function. Output the received sequence of real numbers in each process.
MPI2Send19°. A real number is given in each process. Change the order of given numbers to inverse one by sending the given numbers from the process 0 to the last process, from the process 1 to the last but one process, …, from the last process to the process 0. Use the MPI_Sendrecv_replace function. Output the received number in each process.
MPI2Send20°. A real number A and its order number N (as an integer) are given in each slave process; the set of integers N contains all values in the range 0 to K − 1, K is the number of processes. Send all numbers A to the master process and output the received numbers in ascending order of their order numbers N. Do not use arrays. Use the order number N as a msgtag parameter of the MPI_Send function.
MPI2Send21°. An integer L (≥ 0) and a sequence of L pairs (A, N) are given in each slave process; A is a real number and N is the order number of A. The sum of all integers L is equal to 2K, where K is the number of processes; the set of integers N contains all values in the range 1 to 2K. Send all numbers A to the master process and output the received numbers in ascending order of their order numbers N. Do not use arrays. Use the order number N as a msgtag parameter of the MPI_Send function.
MPI2Send22°. A sequence of pairs (T, A) is given in the master process; the size of sequence is equal to the number of slave processes. An integer T is equal to 0 or 1; if T = 0 then A is an integer, otherwise A is a real number. Send one of the numbers A to the corresponding slave process (the first number to the process 1, the second number to the process 2, and so on) and output received numbers in the slave processes. Use the value of T as a msgtag parameter of the MPI_Send function to send information about the type of number A; use the MPI_Probe function with the parameter MPI_ANY_TAG to receive this information. Note. To avoid the code duplication, use the auxiliary template functions template <typename T> void send (int t, int dest, MPI_Datatype d) to send data and template <typename T> void recv (MPI_Datatype d) to receive data. Use a number equal to 0 or 1 for the t parameter and the rank of receiving process for the dest parameter.
MPI2Send23°. Two integers T, N and a sequence of N numbers are given in each slave process. An integer T is equal to 0 or 1; if T = 0 then the given sequence contains integers, otherwise it contains real numbers. Send all given sequences to the master process and output received numbers in the ascending order of ranks of sending processes. Use the value of T as a msgtag parameter of the MPI_Send function to send information about the sequence type; use the MPI_Probe function with the parameter MPI_ANY_TAG to receive this information. Note. To avoid the code duplication, use the auxiliary template functions template <typename T> void send(int t, MPI_Datatype d) to send data and template <typename T> void recv(MPI_Datatype d, MPI_Status s) to receive data. Use a number equal to 0 or 1 for the t parameter and the result returned by the MPI_Probe function for the s parameter.
MPI2Send24°. The number of processes K is an even number: K = 2N. A sequence of N real numbers is given in each evenrank process (0, 2, …, K − 2), a sequence of N integers is given in each oddrank process (1, 3, …, K − 1). Using the MPI_Sendrecv_replace function, ðerform the cyclic shift of all realvalued sequences in the direction of increasing the ranks of processes and the cyclic shift of all integer sequences in the direction of decreasing the ranks of processes (that is, the realvalued sequences should be sent from the process 0 to the process 2, from the process 2 to the process 4, …, from the process K − 2 to the process 0 and the integer sequences should be sent from the process K − 1 to the process K − 3, from the process K − 3 to the process K − 5, …, from the process 1 to the process K − 1). Output received data in each process. To determine the rank of the receiving process, use the expression containing the % operator of taking the remainder after integer division. Use the MPI_ANY_SOURCE parameter as the rank of sending process. Note. To avoid the code duplication, use the auxiliary template function template <typename T> void sendrecv(int rank, int size, MPI_Datatype d, int step). The step parameter specifies a shift value, which should be equal to 2 for realvalued sequences and equal to −2 for integer ones.
MPI2Send25°. The number of processes K is an even number: K = 2N. A sequence of R + 1 integers is given in the first half of the processes, where R is the process rank (R = 0, 1, …, N − 1). A sequence of 2N − R real numbers is given in the second half of the processes, where R is the process rank (R = N, N + 1, …, 2N − 1). Using the MPI_Sendrecv function, send the given seguences from each half of the processes to the corresponding process of the other half (that is, the sequence from the process 0 should be sent to the process N, from the process 1 — to the process N + 1, from the process N — to the process 0, from the process 2N − 1 — to the process N − 1, and so on). Output received data in each process. Note. To avoid the code duplication, use the auxiliary template function template <typename T1, typename T2> void sendrecv(MPI_Datatype d1, int cnt1, int rank2, MPI_Datatype d2, int cnt2), where the d1 and cnt1 parameters define the properties of the process that calls the function (the type and the number of elements of sending sequence) and the parameters rank2, d2, cnt2 are the rank and the similar properties of the process involved in data exchange.
Nonblocking communications
MPI2Send26°. An integer N is given in each process. The value of N is equal to 0 in all processes, except for one, and it is equal to 1 in some selected process. Also an integer sequence A of size K − 1 is given in the selected process, where K is the number of processes. Do not save the sequence A in array. Send one element of the sequence A at a time to other processes in ascending order of their ranks and output the received number in each process. Use the required number of the MPI_Issend and MPI_Wait function calls (sending a message in synchronous nonblocking mode) in the selected process and the MPI_Recv function call in the other processes. Additionally, display the duration of each MPI_Wait function call (in milliseconds) in the debug section. To do this, call the MPI_Wtime function before and after the MPI_Wait call and use the Show function to display the difference between returned values of the MPI_Wtime function multiplied by 1000. Check how the debugging information changes if the MPI_Isend function (sending a message in standard nonblocking mode) will be used instead of the MPI_Issend function.
MPI2Send27°. An integer N is given in each process. The value of N is equal to −1 in some selected process of the rank R and it is equal to R in the other processes. A real number A is also given in all processes, except for the selected one. Send the numbers A to the selected process and output received numbers in ascending order of ranks of sending processes. Use the required number of the MPI_Recv function calls in the selected process and the MPI_Issend and MPI_Test function call in the other processes. Repeat the MPI_Test function call until it returns a nonzero flag, and display the required number of iterations of the loop in the debug section using the Show function. Check how the debugging information changes if the MPI_Isend function will be used instead of the MPI_Issend function.
MPI2Send28°. An integer N is given in each process. The value of N is equal to −1 in some selected process of the rank R and it is equal to R in the other processes. A real number A is also given in all processes, except for the selected one. Send the numbers A to the selected process and output received numbers in descending order of ranks of sending processes. Use the required number of the MPI_Irecv and MPI_Test function calls (receiving a message in nonblocking mode) in the selected process and the MPI_Ssend function call in the other processes. Repeat the MPI_Test function call after each MPI_Irecv function call until MPI_Test returns a nonzero flag, and display the required number of iterations of the loop in the debug section using the Show function. Check how the debugging information changes if the MPI_Send function will be used instead of the MPI_Ssend function.
MPI2Send29°. An integer N is given in each process. The value of N is equal to −1 in some selected process of the rank R and it is equal to R in the other processes. A real number A is also given in all processes, except for the selected one. Send the numbers A to the selected process and output the sum S of received numbers. Use the required number of the MPI_Irecv and MPI_Waitany function calls in the selected process and the MPI_Ssend function call in the other processes. Declare an array Q of the MPI_Request type in the selected process and call the MPI_Irecv functions in a loop with the a separate element of Q for each function call. Then call the MPI_Waitany function in a second loop to accumulate the sum S. Additionally, display the following data in the debug section in each iteration of the second loop (using the Show and ShowLine function call): the value of A added to the sum at this iteration, and the rank of the process that sent this value.
MPI2Send30°. An integer N is given in each process. The value of N is equal to 0 in all processes, except for two, and it is equal to 1 in the first selected process (the sender) and it is equal to 2 in the second selected process (the receiver). Also an integer R and a sequence of K integers are given in the sender, where R is the rank of the receiver and K is the number of processes. Do not save the sequence A in array. Send all elements of the sequence A to the receiver and output the received numbers in the same order. Use the single call of the MPI_Ssend_init function and the required number of the MPI_Start and MPI_Wait function calls in the sender, and the single call of the MPI_Recv_init function and the required number of the MPI_Start and MPI_Wait function calls in the receiver. Additionally, display the duration of each MPI_Wait function call (in milliseconds) in the debug section (for both the sender and the receiver). To do this, call the MPI_Wtime function before and after the MPI_Wait call and use the Show function to display the difference between returned values of the MPI_Wtime function multiplied by 1000. Check how the debugging information changes if the MPI_Send_init function will be used instead of the MPI_Ssend_init function.
MPI2Send31°. An integer N is given in each process. The value of N is equal to 2 in the first selected process (the receiver), it is equal to 1 in some other selected processes (the senders), it is equal to 0 in all other processes. Also an integer R and a sequence A of K integers are given in each sender, where R is the rank of the receiver and K is the number of processes, and the number of senders C is given in the receiver. Send all sequences A to the receiver and output the sums S of elements of all sequences A with the same indices (in ascending order of indices). Use the single call of the MPI_Ssend function in each sender. Declare an array Q of the MPI_Request type in the receiver and call the MPI_Recv_init functions in a loop with a separate element of Q for each function call. Then call the MPI_Startall function in the receiver and, after that, call the MPI_Waitany function in a second loop to accumulate the sums S. Additionally, display the following data in the debug section in each iteration of the second loop (using two Show function and one ShowLine function calls): the duration of each MPI_Waitany function call (in milliseconds), the returned value of the third parameter (named index) of the MPI_Waitany function, and the rank of current sender that corresponds to the index parameter. To find the duration, call the MPI_Wtime function before and after the MPI_Waitany call and calculate the difference between returned values of the MPI_Wtime function multiplied by 1000. To find the rank of the current sender, use the value of the last parameter (of the MPI_Status type) returned by the MPI_Waitany function.
MPI2Send32°. An integer N is given in each process. The value of N is equal to 1 in the first selected process (the sender), it is equal to 2 in some other selected processes (the receivers), it is equal to 0 in all other processes. Also a real number A, an integer C, and a sequence R of C integers are given in the sender, where C is the number of receivers and R contains ranks of all receivers. Send the number A to all receivers and output it in each receiver. Use the single call of the MPI_Recv function in each receiver. Declare an array Q of the MPI_Request type in the sender and call the MPI_Ssend_init functions in a loop with a separate element of Q for each function call. Then call the MPI_Startall function in the sender and, after that, call the MPI_Testany function in a second loop (the MPI_Testany function should be called in a nested loop until it returns a nonzero flag). Additionally, display the following data in the debug section in each iteration of the second loop (using the Show and ShowLine function call): the returned value of the third parameter (named index) of the MPI_Testany function (when it returns a nonzero flag), and the number of MPI_Testany function calls (that is, the number of iterations of the nested loop). Check how the debugging information changes if the MPI_Send_init function will be used instead of the MPI_Ssend_init function.
