hmmer-3.3/easel/esl_mpi.c
/* Function:  esl_mpi_PackOpt()
 * Synopsis:  Pack an optional, variable-sized array (or string).
 * Incept:    SRE, Sat Jun  2 08:40:39 2007 [Janelia]
 *
 * Purpose:   Pack data array <inbuf> of <incount> elements of type <type> into
 *            an MPI packed buffer <pack_buf> of total size <pack_buf_size> destined
 *            for MPI communicator <comm> that is currently filled to position <*position>.
 *            
 *            <inbuf> may be <NULL>, in which case <incount> is
 *            assumed to be 0, and a `null array' is packed that
 *            <esl_mpi_UnpackOpt()> knows how to decode as a <NULL>
 *            pointer.
 *            
 *            As a special case for strings, if <type> is <MPI_CHAR>,
 *            <incount> may be passed as <-1> to indicate `unknown';
 *            the routine will use <strlen(inbuf)+1> to determine the
 *            size of the string including its <NUL> terminator.
 *
 * Returns:   <eslOK> on success, the array is packed into <pack_buf>, 
 *            and the <*position> counter is updated to point to the next byte
 *            in <pack_buf> after the packed array.
 * 
 * Throws:    <eslESYS> if an MPI call fails.
 */
esl_mpi_PackOpt()
Synopsis:  Pack an optional, variable-sized array (or string).

Pack data array  of  elements of type  into
an MPI packed buffer  of total size  destined
for MPI communicator  that is currently filled to position <*position>.

 may be , in which case  is
assumed to be 0, and a `null array' is packed that
 knows how to decode as a 
pointer.

As a special case for strings, if  is ,
 may be passed as <-1> to indicate `unknown';
the routine will use  to determine the
size of the string including its  terminator.

 on success, the array is packed into ,
and the <*position> counter is updated to point to the next byte
in  after the packed array.

 if an MPI call fails.
esl_mpi_PackOpt () Synopsis : Pack an optional variable - sized array ( or string ) . Pack data array of elements of type into an MPI packed buffer of total size destined for MPI communicator that is currently filled to position < * position > . may be in which case is assumed to be 0 and a ` null array ' is packed that knows how to decode as a pointer . As a special case for strings if is may be passed as < - 1 > to indicate ` unknown ' ; the routine will use to determine the size of the string including its terminator . on success the array is packed into and the < * position > counter is updated to point to the next byte in after the packed array . if an MPI call fails .
int
esl_mpi_PackOpt(void *inbuf, int incount, MPI_Datatype type, void *pack_buf, int pack_buf_size, int *position, MPI_Comm comm)
{
  if (inbuf == NULL) {
    incount = 0;
    if (MPI_Pack(&incount,    1, MPI_INT, pack_buf, pack_buf_size, position, comm) != 0)  ESL_EXCEPTION(eslESYS, "MPI pack failed");
  } else {
    if (incount == -1 && type == MPI_CHAR) incount = strlen(inbuf) + 1;
    if (MPI_Pack(&incount,    1, MPI_INT, pack_buf, pack_buf_size, position, comm) != 0)  ESL_EXCEPTION(eslESYS, "MPI pack failed");
    if (MPI_Pack(inbuf, incount,    type, pack_buf, pack_buf_size, position, comm) != 0)  ESL_EXCEPTION(eslESYS, "MPI pack failed");
  }
  return eslOK;
}
int esl_mpi_PackOpt ( void * inbuf , int incount , MPI_Datatype type , void * pack_buf , int pack_buf_size , int * position , MPI_Comm comm ) { if ( inbuf == NULL ) { incount = 0 ; if ( MPI_Pack ( & incount , 1 , MPI_INT , pack_buf , pack_buf_size , position , comm ) != 0 ) ESL_EXCEPTION ( eslESYS , " " ) ; } else { if ( incount == -1 && type == MPI_CHAR ) incount = strlen ( inbuf ) + 1 ; if ( MPI_Pack ( & incount , 1 , MPI_INT , pack_buf , pack_buf_size , position , comm ) != 0 ) ESL_EXCEPTION ( eslESYS , " " ) ; if ( MPI_Pack ( inbuf , incount , type , pack_buf , pack_buf_size , position , comm ) != 0 ) ESL_EXCEPTION ( eslESYS , " " ) ; } return eslOK ; }
Function:  esl_mpi_PackOpt()
 Synopsis:  Pack an optional, variable-sized array (or string).
Function : esl_mpi_PackOpt () Synopsis : Pack an optional variable - sized array ( or string ) .