FORM  4.2.1
Data Structures | Macros | Typedefs | Functions | Variables
mpi.c File Reference
#include <limits.h>
#include "form3.h"

Go to the source code of this file.

Data Structures

struct  longMultiStruct
 

Macros

#define PF_PACKSIZE   1600
 
#define MPI_ERRCODE_CHECK(err)
 

Typedefs

typedef struct longMultiStruct PF_LONGMULTI
 

Functions

LONG PF_RealTime (int i)
 
int PF_LibInit (int *argcp, char ***argvp)
 
int PF_LibTerminate (int error)
 
int PF_Probe (int *src)
 
int PF_ISendSbuf (int to, int tag)
 
int PF_RecvWbuf (WORD *b, LONG *s, int *src)
 
int PF_IRecvRbuf (PF_BUFFER *r, int bn, int from)
 
int PF_WaitRbuf (PF_BUFFER *r, int bn, LONG *size)
 
int PF_Bcast (void *buffer, int count)
 
int PF_RawSend (int dest, void *buf, LONG l, int tag)
 
LONG PF_RawRecv (int *src, void *buf, LONG thesize, int *tag)
 
int PF_RawProbe (int *src, int *tag, int *bytesize)
 
int PF_PrintPackBuf (char *s, int size)
 
int PF_PreparePack (void)
 
int PF_Pack (const void *buffer, size_t count, MPI_Datatype type)
 
int PF_Unpack (void *buffer, size_t count, MPI_Datatype type)
 
int PF_PackString (const UBYTE *str)
 
int PF_UnpackString (UBYTE *str)
 
int PF_Send (int to, int tag)
 
int PF_Receive (int src, int tag, int *psrc, int *ptag)
 
int PF_Broadcast (void)
 
int PF_PrepareLongSinglePack (void)
 
int PF_LongSinglePack (const void *buffer, size_t count, MPI_Datatype type)
 
int PF_LongSingleUnpack (void *buffer, size_t count, MPI_Datatype type)
 
int PF_LongSingleSend (int to, int tag)
 
int PF_LongSingleReceive (int src, int tag, int *psrc, int *ptag)
 
int PF_PrepareLongMultiPack (void)
 
int PF_LongMultiPackImpl (const void *buffer, size_t count, size_t eSize, MPI_Datatype type)
 
int PF_LongMultiUnpackImpl (void *buffer, size_t count, size_t eSize, MPI_Datatype type)
 
int PF_LongMultiBroadcast (void)
 

Variables

LONG PF_maxDollarChunkSize = 0
 

Detailed Description

MPI dependent functions of parform

This file contains all the functions for the parallel version of form3 that explicitly need to call mpi routines. This is the only file that really needs to be linked to the mpi-library!

Definition in file mpi.c.

Macro Definition Documentation

#define MPI_ERRCODE_CHECK (   err)
Value:
do { \
int _tmp_err = (err); \
if ( _tmp_err != MPI_SUCCESS ) return _tmp_err != 0 ? _tmp_err : -1; \
} while (0)

A macro which exits the caller with a non-zero return value if err is not MPI_SUCCESS.

Parameters
errThe return value of a MPI function to be checked.
Remarks
The MPI standard defines MPI_SUCCESS == 0. Then (_tmp_err == 0) appears twice and we can expect the second evaluation will be eliminated by the compiler optimization.

Definition at line 84 of file mpi.c.

Referenced by PF_Broadcast(), PF_Pack(), PF_Receive(), PF_Send(), and PF_Unpack().

Function Documentation

LONG PF_RealTime ( int  i)

Returns the realtime in 1/100 sec. as a LONG.

Parameters
ithe timer will be reset if i == 0.
Returns
the real elapsed time in 1/100 second.

Definition at line 101 of file mpi.c.

Referenced by PF_Init().

int PF_LibInit ( int *  argcp,
char ***  argvp 
)

Performs all library dependent initializations.

Parameters
argcppointer to the number of arguments.
argvppointer to the arguments.
Returns
0 if OK, nonzero on error.

Definition at line 123 of file mpi.c.

Referenced by PF_Init().

int PF_LibTerminate ( int  error)

Exits mpi, when there is an error either indicated or happening, returnvalue is 1, else returnvalue is 0.

Parameters
erroran error code.
Returns
0 if OK, nonzero on error.

Definition at line 209 of file mpi.c.

Referenced by PF_Terminate().

int PF_Probe ( int *  src)

Probes the next incoming message. If src == PF_ANY_SOURCE this operation is blocking, otherwise nonbloking.

Parameters
[in,out]srcthe source process number. In output, the process number of actual found source.
Returns
the tag value of the next incoming message if found, 0 if a nonbloking probe (input src != PF_ANY_SOURCE) did not find any messages. A negative returned value indicates an error.

Definition at line 230 of file mpi.c.

int PF_ISendSbuf ( int  to,
int  tag 
)

Nonblocking send operation. It sends everything from buff to fill of the active buffer. Depending on tag it also can do waiting for other sends to finish or set the active buffer to the next one.

Parameters
tothe destination process number.
tagthe message tag.
Returns
0 if OK, nonzero on error.

Definition at line 261 of file mpi.c.

Referenced by FlushOut(), PF_Processor(), and PutOut().

int PF_RecvWbuf ( WORD *  b,
LONG *  s,
int *  src 
)

Blocking receive of a WORD buffer.

Parameters
[out]bthe buffer to store the received data.
[in,out]sthe size of the buffer. The output value is the actual size of the received data.
[in,out]srcthe source process number. The output value is the process number of actual source.
Returns
the received message tag. A negative value indicates an error.

Definition at line 337 of file mpi.c.

int PF_IRecvRbuf ( PF_BUFFER r,
int  bn,
int  from 
)

Posts nonblocking receive for the active receive buffer. The buffer is filled from full to stop.

Parameters
rthe PF_BUFFER struct for the nonblocking receive.
bnthe index of the cyclic buffer.
fromthe source process number.
Returns
0 if OK, nonzero on error.

Definition at line 366 of file mpi.c.

int PF_WaitRbuf ( PF_BUFFER r,
int  bn,
LONG *  size 
)

Waits for the buffer bn to finish a pending nonblocking receive. It returns the received tag and in *size the number of field received. If the receive is already finished, just return the flag and size, else wait for it to finish, but also check for other pending receives.

Parameters
rthe PF_BUFFER struct for the pending nonblocking receive.
bnthe index of the cyclic buffer.
[out]sizethe actual size of received data.
Returns
the received message tag. A negative value indicates an error.

Definition at line 400 of file mpi.c.

int PF_Bcast ( void *  buffer,
int  count 
)

Broadcasts a message from the master to slaves.

Parameters
[in,out]bufferthe starting address of buffer. The contents in this buffer on the master will be transferred to those on the slaves.
countthe length of the buffer in bytes.
Returns
0 if OK, nonzero on error.

Definition at line 440 of file mpi.c.

Referenced by PF_BroadcastBuffer(), and PF_BroadcastNumber().

int PF_RawSend ( int  dest,
void *  buf,
LONG  l,
int  tag 
)

Sends l bytes from buf to dest. Returns 0 on success, or -1.

Parameters
destthe destination process number.
bufthe send buffer.
lthe size of data in the send buffer in bytes.
tagthe message tag.
Returns
0 if OK, nonzero on error.

Definition at line 463 of file mpi.c.

Referenced by PF_MUnlock(), and PF_SendFile().

LONG PF_RawRecv ( int *  src,
void *  buf,
LONG  thesize,
int *  tag 
)

Receives not more than thesize bytes from src, returns the actual number of received bytes, or -1 on failure.

Parameters
[in,out]srcthe source process number. In output, that of the actual received message.
[out]bufthe receive buffer.
thesizethe size of the receive buffer in bytes.
[out]tagthe message tag of the actual received message.
Returns
the actual sizeof received data in bytes, or -1 on failure.

Definition at line 484 of file mpi.c.

Referenced by PF_RecvFile().

int PF_RawProbe ( int *  src,
int *  tag,
int *  bytesize 
)

Probes an incoming message.

Parameters
[in,out]srcthe source process number. In output, that of the actual received message.
[in,out]tagthe message tag. In output, that of the actual received message.
[out]bytesizethe size of incoming data in bytes.
Returns
0 if OK, nonzero on error.

Definition at line 508 of file mpi.c.

int PF_PrintPackBuf ( char *  s,
int  size 
)

Prints the contents in the pack buffer.

Parameters
sa message to be shown.
sizethe length of the buffer to be shown.
Returns
0 if OK, nonzero on error.

Definition at line 594 of file mpi.c.

int PF_PreparePack ( void  )

Prepares for the next pack operations on the sender.

Returns
0 if OK, nonzero on error.

Definition at line 624 of file mpi.c.

Referenced by PF_BroadcastPreDollar(), PF_BroadcastString(), and PF_Init().

int PF_Pack ( const void *  buffer,
size_t  count,
MPI_Datatype  type 
)

Adds data into the pack buffer.

Parameters
bufferthe pointer to the buffer storing the data to be packed.
countthe number of elements in the buffer.
typethe data type of elements in the buffer.
Returns
0 if OK, nonzero on error.

Definition at line 642 of file mpi.c.

References MPI_ERRCODE_CHECK.

Referenced by PF_BroadcastPreDollar(), and PF_Init().

int PF_Unpack ( void *  buffer,
size_t  count,
MPI_Datatype  type 
)

Retrieves the next data in the pack buffer.

Parameters
[out]bufferthe pointer to the buffer to store the unpacked data.
countthe number of elements of data to be received.
typethe data type of elements of data to be received.
Returns
0 if OK, nonzero on error.

Definition at line 671 of file mpi.c.

References MPI_ERRCODE_CHECK.

Referenced by PF_BroadcastPreDollar(), and PF_Init().

int PF_PackString ( const UBYTE *  str)

Packs a string str into the packed buffer PF_packbuf, including the trailing zero.

The first element (PF_INT) is the length of the packed portion of the string. If the string does not fit to the buffer PF_packbuf, the function packs only the initial portion. It returns the number of packed bytes, so if (str[length-1]=='\0') then the whole string fits to the buffer, if not, then the rest (str+length) bust be packed and send again. On error, the function returns the negative error code.

One exception: the string "\0!\0" is used as an image of the NULL, so all 3 characters will be packed.

Parameters
stra string to be packed.
Returns
the number of packed bytes, or a negative value on failure.

Definition at line 706 of file mpi.c.

Referenced by PF_BroadcastString().

int PF_UnpackString ( UBYTE *  str)

Unpacks a string to str from the packed buffer PF_packbuf, including the trailing zero.

It returns the number of unpacked bytes, so if (str[length-1]=='\0') then the whole string was unpacked, if not, then the rest must be appended to (str+length). On error, the function returns the negative error code.

Parameters
[out]strthe buffer to store the unpacked string
Returns
the number of unpacked bytes, or a negative value on failure.

Definition at line 774 of file mpi.c.

Referenced by PF_BroadcastString().

int PF_Send ( int  to,
int  tag 
)

Sends the contents in the pack buffer to the process specified by to.

Example:

* if ( PF.me == SRC ) {
* // Packing operations here...
* PF_Send(DEST, TAG);
* }
* else if ( PF.me == DEST ) {
* PF_Receive(SRC, TAG, &actual_src, &actual_tag);
* // Unpacking operations here...
* }
*
Parameters
tothe destination process number.
tagthe message tag.
Returns
0 if OK, nonzero on error.

Definition at line 822 of file mpi.c.

References MPI_ERRCODE_CHECK.

int PF_Receive ( int  src,
int  tag,
int *  psrc,
int *  ptag 
)

Receives data into the pack buffer from the process specified by src. This function allows &src == psrc or &tag == ptag. Either psrc or ptag can be NULL.

See the example of PF_Send().

Parameters
srcthe source process number (can be PF_ANY_SOURCE).
tagthe source message tag (can be PF_ANY_TAG).
[out]psrcthe actual source process number of received message.
[out]ptagthe received message tag.
Returns
0 if OK, nonzero on error.

Definition at line 848 of file mpi.c.

References MPI_ERRCODE_CHECK.

int PF_Broadcast ( void  )

Broadcasts the contents in the pack buffer on the master to those on the slaves.

Example:

* if ( PF.me == MASTER ) {
* // Packing operations here...
* }
* if ( PF.me != MASTER ) {
* // Unpacking operations here...
* }
*
Returns
0 if OK, nonzero on error.

Definition at line 883 of file mpi.c.

References MPI_ERRCODE_CHECK.

Referenced by PF_BroadcastPreDollar(), PF_BroadcastString(), and PF_Init().

int PF_PrepareLongSinglePack ( void  )

Prepares for the next long-single-pack operations on the sender.

Returns
0 if OK, nonzero on error.

Definition at line 1451 of file mpi.c.

Referenced by PF_CollectModifiedDollars(), and PF_Processor().

int PF_LongSinglePack ( const void *  buffer,
size_t  count,
MPI_Datatype  type 
)

Adds data into the "long single" pack buffer.

Parameters
bufferthe pointer to the buffer storing the data to be packed.
countthe number of elements in the buffer.
typethe data type of elements in the buffer.
Returns
0 if OK, nonzero on error.

Definition at line 1469 of file mpi.c.

Referenced by PF_CollectModifiedDollars(), and PF_Processor().

int PF_LongSingleUnpack ( void *  buffer,
size_t  count,
MPI_Datatype  type 
)

Retrieves the next data in the "long single" pack buffer.

Parameters
[out]bufferthe pointer to the buffer to store the unpacked data.
countthe number of elements of data to be received.
typethe data type of elements of data to be received.
Returns
0 if OK, nonzero on error.

Definition at line 1503 of file mpi.c.

Referenced by PF_CollectModifiedDollars(), and PF_Processor().

int PF_LongSingleSend ( int  to,
int  tag 
)

Sends the contents in the "long single" pack buffer to the process specified by to.

Example:

* if ( PF.me == SRC ) {
* // Packing operations here...
* PF_LongSingleSend(DEST, TAG);
* }
* else if ( PF.me == DEST ) {
* PF_LongSingleReceive(SRC, TAG, &actual_src, &actual_tag);
* // Unpacking operations here...
* }
*
Parameters
tothe destination process number.
tagthe message tag.
Returns
0 if OK, nonzero on error.

Definition at line 1540 of file mpi.c.

Referenced by PF_CollectModifiedDollars(), and PF_Processor().

int PF_LongSingleReceive ( int  src,
int  tag,
int *  psrc,
int *  ptag 
)

Receives data into the "long single" pack buffer from the process specified by src. This function allows &src == psrc or &tag == ptag. Either psrc or ptag can be NULL.

See the example of PF_LongSingleSend().

Parameters
srcthe source process number (can be PF_ANY_SOURCE).
tagthe source message tag (can be PF_ANY_TAG).
[out]psrcthe actual source process number of received message.
[out]ptagthe received message tag.
Returns
0 if OK, nonzero on error.

Definition at line 1583 of file mpi.c.

Referenced by PF_CollectModifiedDollars(), and PF_Processor().

int PF_PrepareLongMultiPack ( void  )

Prepares for the next long-multi-pack operations on the sender.

Returns
0 if OK, nonzero on error.

Definition at line 1643 of file mpi.c.

Referenced by PF_BroadcastCBuf(), PF_BroadcastExpFlags(), PF_BroadcastModifiedDollars(), and PF_BroadcastRedefinedPreVars().

int PF_LongMultiPackImpl ( const void *  buffer,
size_t  count,
size_t  eSize,
MPI_Datatype  type 
)

Adds data into the "long multi" pack buffer.

Parameters
bufferthe pointer to the buffer storing the data to be packed.
countthe number of elements in the buffer.
eSizethe byte size of each element of data.
typethe data type of elements in the buffer.
Returns
0 if OK, nonzero on error.

Definition at line 1662 of file mpi.c.

References PF_LongMultiPackImpl().

Referenced by PF_LongMultiPackImpl().

int PF_LongMultiUnpackImpl ( void *  buffer,
size_t  count,
size_t  eSize,
MPI_Datatype  type 
)

Retrieves the next data in the "long multi" pack buffer.

Parameters
[out]bufferthe pointer to the buffer to store the unpacked data.
countthe number of elements of data to be received.
eSizethe byte size of each element of data.
typethe data type of elements of data to be received.
Returns
0 if OK, nonzero on error.

Definition at line 1721 of file mpi.c.

References PF_LongMultiUnpackImpl().

Referenced by PF_LongMultiUnpackImpl().

int PF_LongMultiBroadcast ( void  )

Broadcasts the contents in the "long multi" pack buffer on the master to those on the slaves.

Example:

* if ( PF.me == MASTER ) {
* // Packing operations here...
* }
* if ( PF.me != MASTER ) {
* // Unpacking operations here...
* }
*
Returns
0 if OK, nonzero on error.

Definition at line 1807 of file mpi.c.

Referenced by PF_BroadcastCBuf(), PF_BroadcastExpFlags(), PF_BroadcastModifiedDollars(), and PF_BroadcastRedefinedPreVars().