|Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications|
by J. Seward, N. Nethercote, J. Weidendorfer and the Valgrind Development Team
Paperback (6"x9"), 164 pages
RRP £12.95 ($19.95)
5.8.5 Writing new MPI function wrappers
For the most part the wrappers are straightforward. The only significant complexity arises with nonblocking receives.
The issue is that ‘MPI_Irecv’ states the recv buffer and returns immediately, giving a handle (‘MPI_Request’) for the transaction. Later the user will have to poll for completion with ‘MPI_Wait’ etc, and when the transaction completes successfully, the wrappers have to paint the recv buffer. But the recv buffer details are not presented to ‘MPI_Wait’---only the handle is. The library therefore maintains a shadow table which associates uncompleted ‘MPI_Request’s with the corresponding buffer address/count/type. When an operation completes, the table is searched for the associated address/count/type info, and memory is marked accordingly.
Access to the table is guarded by a (POSIX pthreads) lock, so as to make the library thread-safe.
The table is allocated with ‘malloc’ and never ‘free’d, so it will show up in leak checks.
Writing new wrappers should be fairly easy. The source file is ‘auxprogs/libmpiwrap.c’. If possible, find an existing wrapper for a function of similar behaviour to the one you want to wrap, and use it as a starting point. The wrappers are organised in sections in the same order as the MPI 1.1 spec, to aid navigation. When adding a wrapper, remember to comment out the definition of the default wrapper in the long list of defaults at the bottom of the file (do not remove it, just comment it out).
|ISBN 0954612051||Valgrind 3.3 - Advanced Debugging and Profiling for GNU/Linux applications||See the print edition|