The functions MPI Pack and MPI Unpack provide an alternative to derived datatypes for grouping data. MPI Pack copies the data to be sent, one block at a time, into a user-provided buffer. The buffer...



The functions MPI Pack and MPI Unpack provide an alternative to derived


datatypes for grouping data. MPI Pack copies the data to be sent, one block at


a time, into a user-provided buffer. The buffer can then be sent and received.


After the data is received, MPI Unpack can be used to unpack it from the


receive buffer. The syntax of MPI Pack is


int MPI Pack(


void∗ in buf /∗ in ∗/,


int in buf count /∗ in ∗/,


MPI Datatype datatype /∗ in ∗/,


void∗ pack buf /∗ out ∗/,


int pack buf sz /∗ in ∗/,


int∗ position p /∗ in/out ∗/,


MPI Comm comm /∗ in ∗/);


We could therefore pack the input data to the trapezoidal rule program with


the following code:


char pack buf[100];


int position = 0;


MPI Pack(&a, 1, MPI DOUBLE, pack buf, 100, &position, comm);


MPI Pack(&b, 1, MPI DOUBLE, pack buf, 100, &position, comm);


MPI Pack(&n, 1, MPI INT, pack buf, 100, &position, comm);


The key is the position argument. When MPI Pack is called, position should


refer to the first available slot in pack buf. When MPI Pack returns, it refers


to the first available slot after the data that was just packed, so after process 0


executes this code, all the processes can call MPI Bcast:


MPI Bcast(pack buf, 100, MPI PACKED, 0, comm);


Note that the MPI datatype for a packed buffer is MPI PACKED. Now the other


processes can unpack the data using: MPI Unpack:


int MPI Unpack(


void∗ pack buf /∗ in ∗/,


int pack buf sz /∗ in ∗/,


int∗ position p /∗ in/out ∗/,


void∗ out buf /∗ out ∗/,


int out buf count /∗ in ∗/,


MPI Datatype datatype /∗ in ∗/,


MPI Comm comm /∗ in ∗/);


This can be used by “reversing” the steps in MPI Pack, that is, the data is


unpacked one block at a time starting with position = 0.


Write another Get input function for the trapezoidal rule program. This


one should use MPI Pack on process 0 and MPI Unpack on the other processes.

May 26, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here