16.2.4. MPI Library Implementation

PreviousUpNext
Up: Profiling Interface Next: Complications Previous: Logic of the Design

If the MPI library is implemented in C on a Unix system, then there are various options, including the two presented here, for supporting the name-shift requirement. The choice between these two options depends partly on whether the linker and compiler support weak symbols.

If the compiler and linker support weak external symbols, then only a single library is required as the following example shows:


Example [Profiling interface, implementation using weak symbols]CProfiling interface!implementation using weak symbols Library implementation using weak symbols.

#pragma weak MPI_Example = PMPI_Example 
 
int PMPI_Example(/* appropriate args */) 
{ 
    /* Useful content */ 
} 

The effect of this #pragma is to define the external symbol MPI_Example as a weak definition. This means that the linker will not complain if there is another definition of the symbol (for instance in the profiling library); however if no other definition exists, then the linker will use the weak definition.

In the absence of weak symbols then one possible solution would be to use the C macro preprocessor as the following example shows:


Example [Profiling interface, implementation using the C macro preprocessor]CProfiling interface!implementation using the C macro preprocessor Library implementation using C pre-processor macros.

#ifdef PROFILELIB 
#    ifdef __STDC__ 
#        define FUNCTION(name) P##name 
#    else 
#        define FUNCTION(name) P/**/name 
#    endif 
#else 
#    define FUNCTION(name) name 
#endif 

Each of the user visible functions in the library would then be declared thus


int FUNCTION(MPI_Example)(/* appropriate args */) 
{ 
    /* Useful content */ 
} 

The same source file can then be compiled to produce both versions of the library, depending on the state of the PROFILELIB macro symbol.

It is required that the standard MPI library be built in such a way that the inclusion of MPI functions can be achieved one at a time. This may mean that each external function must reside in its own compilation unit. This is necessary so that the author of the profiling library need only define those MPI functions that need to be intercepted, references to any others being fulfilled by the normal MPI library.


Example

The following example shows a potential link step when using the profiling interface.


% cc ... -lmyprof -lpmpi -lmpi 

Here libmyprof.a contains the profiler functions that intercept some of the MPI functions, libpmpi.a contains the ``name shifted'' MPI functions, and libmpi.a contains the normal definitions of the MPI functions.


PreviousUpNext
Up: Profiling Interface Next: Complications Previous: Logic of the Design


Return to MPI-5.0 Standard Index
Return to MPI Forum Home Page

(Unofficial) MPI-5.0 of June 9, 2025
HTML Generated on March 2, 2025