Blob Blame History Raw
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML3.2 EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="DOCTEXT">
<TITLE>MPI_Buffer_attach</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
<H1 id="MPI_Buffer_attach">MPI_Buffer_attach</H1>
Attaches a user-provided buffer for sending 
<H2>Synopsis</H2>
<PRE>
int MPI_Buffer_attach(void *buffer, int size)
</PRE>
<H2>Input Parameters</H2>
<DL>
<DT><B>buffer </B> <DD> initial buffer address (choice)

<DT><B>size </B> <DD> buffer size, in bytes (integer)
</DL>
<P>
<H2>Notes</H2>
The size given should be the sum of the sizes of all outstanding Bsends that
you intend to have, plus <tt>MPI_BSEND_OVERHEAD</tt> for each Bsend that you do.
For the purposes of calculating size, you should use <tt>MPI_Pack_size</tt>.
In other words, in the code
<PRE>
     MPI_Buffer_attach(buffer, size);
     MPI_Bsend(..., count=20, datatype=type1,  ...);
     ...
     MPI_Bsend(..., count=40, datatype=type2, ...);
</PRE>

the value of <tt>size</tt> in the <tt>MPI_Buffer_attach</tt> call should be greater than
the value computed by
<PRE>
     MPI_Pack_size(20, type1, comm, &amp;s1);
     MPI_Pack_size(40, type2, comm, &amp;s2);
     size = s1 + s2 + 2 * MPI_BSEND_OVERHEAD;
</PRE>

The <tt>MPI_BSEND_OVERHEAD</tt> gives the maximum amount of space that may be used in
the buffer for use by the BSEND routines in using the buffer.  This value
is in <tt>mpi.h</tt> (for C) and <tt>mpif.h</tt> (for Fortran).
<P>
<H2>Thread and Interrupt Safety</H2>
<P>
The user is responsible for ensuring that multiple threads do not try to
update the same MPI object from different threads.  This routine should
not be used from within a signal handler.
<P>
The MPI standard defined a thread-safe interface but this does not
mean that all routines may be called without any thread locks.  For
example, two threads must not attempt to change the contents of the
same <tt>MPI_Info</tt> object concurrently.  The user is responsible in this
case for using some mechanism, such as thread locks, to ensure that
only one thread at a time makes use of this routine.
Because the buffer for buffered sends (e.g., <tt>MPI_Bsend</tt>) is shared by all
threads in a process, the user is responsible for ensuring that only
one thread at a time calls this routine or <tt>MPI_Buffer_detach</tt>.
<P>
<H2>Notes for Fortran</H2>
All MPI routines in Fortran (except for <tt>MPI_WTIME</tt> and <tt>MPI_WTICK</tt>) have
an additional argument <tt>ierr</tt> at the end of the argument list.  <tt>ierr
</tt>is an integer and has the same meaning as the return value of the routine
in C.  In Fortran, MPI routines are subroutines, and are invoked with the
<tt>call</tt> statement.
<P>
All MPI objects (e.g., <tt>MPI_Datatype</tt>, <tt>MPI_Comm</tt>) are of type <tt>INTEGER
</tt>in Fortran.
<P>
<H2>Errors</H2>
<P>
All MPI routines (except <tt>MPI_Wtime</tt> and <tt>MPI_Wtick</tt>) return an error value;
C routines as the value of the function and Fortran routines in the last
argument.  Before the value is returned, the current MPI error handler is
called.  By default, this error handler aborts the MPI job.  The error handler
may be changed with <tt>MPI_Comm_set_errhandler</tt> (for communicators),
<tt>MPI_File_set_errhandler</tt> (for files), and <tt>MPI_Win_set_errhandler</tt> (for
RMA windows).  The MPI-1 routine <tt>MPI_Errhandler_set</tt> may be used but
its use is deprecated.  The predefined error handler
<tt>MPI_ERRORS_RETURN</tt> may be used to cause error values to be returned.
Note that MPI does <em>not</em> guarentee that an MPI program can continue past
an error; however, MPI implementations will attempt to continue whenever
possible.
<P>
<DL>
<DT><B>MPI_SUCCESS </B> <DD> No error; MPI routine completed successfully.
</DL>
<DL>
<DT><B>MPI_ERR_BUFFER </B> <DD> Invalid buffer pointer.  Usually a null buffer where
one is not valid.
</DL>
<DL>
<DT><B>MPI_ERR_INTERN </B> <DD> An internal error has been detected.  This is fatal.
Please send a bug report to <tt>mpi-bugs@mcs.anl.gov</tt>.
</DL>
<P>
<H2>See Also</H2>
 MPI_Buffer_detach, MPI_Bsend
<br>
</BODY></HTML>