IBM Books

MPI Programming Guide


MPI nameshift profiling

To use nameshift profiling routines that are either written to the C bindings with an MPI program written in C or that are written to the FORTRAN bindings with an MPI program written in FORTRAN, follow the steps in Using the signal-handling library or Using the threads library.

Using the signal-handling library

Programs that use the C MPI language bindings can easily create profiling libraries using the name-shifted interface.

Follow the appropriate steps:

  1. Create a source file that contains profiling versions of all the MPI routines you want to profile. For example, create a source file called myprof.c that contains the following code:
    #include <stdio.h>
    #include <mpi.h>
    int MPI_Init(int *argc, char ***argv) {
      int rc;
     
      printf("hello from profiling layer MPI_Init...\n");
      rc = PMPI_Init(argc, argv);
      printf("goodbye from profiling layer MPI_Init...\n");
      return(rc);
    }
    
  2. Create an export file that contains all of the symbols your profiling library will export. Begin this file with the name of your profiling library and the name of the .o file that will contain the object code of your profiling routines. For example, create a file called myprof.exp that contains this statement:
    MPI_Init
    
  3. Compile the source file that contains your profiling MPI routines. For example:
    cc -c myprof.c -I/usr/lpp/ppe.poe/include
    

    The -I flag defines the location of mpi.h.

  4. Create a shared library called libmyprof.a that contains the profiled versions, exporting their symbols and linking with the PE MPI library using myprof.exp. For example:
    ld -o newmyprof.o myprof.o -bM:SRE -H512 -T512 -bnoentry -bE:myprof.exp 
      -lc -lmpi -L/usr/lpp/ppe.poe/lib
    ar rv libmyprof.a newmyprof.o
    
  5. Link your user program:
    mpcc -o test1 test1.c -L. -lmyprof
    
  6. Run the resulting executable.
  7. Programs that use the FORTRAN MPI language bindings need to do some additional steps to use the profiling libraries created above. This is because the FORTRAN bindings are contained in a separate shared object from the C bindings.

    The shipped product has a library structure that looks like this:

    	+---------------------+		exports mpi_aaa
    	| libmpi.a(mpifort.o) |		imports MPI_Aaa    
    	+---------------------+    
                      |   
                      |   
                      |   
    	+---------------------+		exports MPI_Aaa 
    	| libmpi.a(mpicore.o) |		exports PMPI_Aaa 
    	+---------------------+
       
       
     
    

    You need to change it into the following structure by rebuilding the mpifort.o shared object:

    	+-------------------------+	exports mpi_aaa
    	| libpmpi.a(newmpifort.o) |	imports MPI_Aaa	
    	+-------------------------+	
                       |
    		   |
    		   |
    	+-------------------------+	exports MPI_Aaa       
    	| libmyprof.a(newmyprof.o)|	imports PMPI_Aaa      
    	+-------------------------+     
                       |
                       |
                       |
    	+---------------------+		 exports PMPI_Aaa
    	| libmpi.a(mpicore.o) |		(exports MPI_Aaa)
    	+---------------------+
     
    

    To do this, first extract mpifort.o from libmpi.a:

    ar -xv /usr/lpp/ppe.poe/lib/libmpi.a mpifort.o
    
  8. Then, construct a script to rebuild mpifort.o, using the AIX rtl_enable command:
    rtl_enable -o newmpifort.o -s mpifort.o -L. -L/usr/lpp/ppe.poe/lib 
      -lmyprof -lmpi -lc
    
  9. The rtl_enable command creates a script called mpifort.sh and import and export files that reflect the original binding with libmpi.a(mpicore.o). To break this binding and rebind, remove the reference to the import file:
    sed "s/-bI:mpifort.imp//" < mpifort.sh > mpifort.newsh
    
  10. Make mpifort.newsh executable and run it:
    chmod +x mpifort.newsh
    mpifort.newsh
    
  11. Archive the new shared object:
    ar rv libpmpi.a newmpifort.o
    
  12. Create a program that uses an MPI function you've profiled. For example, a file called hwinit.f could contain these statements:
     c -------------------------------------
           program  hwinit
           include 'mpif.h'
           integer forterr
     c
           call MPI_INIT(forterr)
     c
     c  Write comments to screen.
     c
           write(6,*)'Hello from task '
     c
           call MPI_FINALIZE(forterr)
     c
           stop
           end
     c
     
    
  13. Link your FORTRAN executable with the new library:
    mpxlf -o hwinit hwinit.f -L. -lpmpi
    
  14. Run the resulting executable.

Using the threads library

Programs that use the C MPI language bindings can easily create profiling libraries using the name-shifted interface.

Follow the appropriate steps:

  1. Create a source file that contains profiling versions of all the MPI subroutines you want to profile. For example, create a source file called myprof_r.c that contains the following code:
    #include <pthread.h>
    #include <stdio.h>
    #include <mpi.h>
    int MPI_Init(int *argc, char ***argv) {
      int rc;
     
      printf("hello from profiling layer MPI_Init...\n");
      rc = PMPI_Init(argc, argv);
      printf("goodbye from profiling layer MPI_Init...\n");
      return(rc);
    }
    
  2. Create an export file that contains all of the symbols your profiling library will export. Begin this file with the name of your profiling library and the name of the .o file that will contain the object code of your profiling routines. For example, create a file called myprof_r.exp that contains this statement:

    MPI_Init
    
  3. Compile the source file that contains your profiling MPI routines. For example:
    cc_r -c myprof_r.c -I/usr/lpp/ppe.poe/include
    

    The -I flag defines the location of mpi.h.

  4. Create a shared library called libmyprof_r.a that contains the profiled versions, exporting their symbols and linking with the PE MPI library, using myprof_r.exp as shown. For example:
    ld -o newmyprof_r.o myprof_r.o -bM:SRE -H512 -T512 -bnoentry
      -bE:myprof_r.exp -lc -lmpi_r -L/usr/lpp/ppe.poe/lib -lpthreads
    ar rv libmyprof_r.a newmyprof_r.o
    
  5. Link your user program:
    mpcc_r -o test1 test1.c -L. -lmyprof_r
    
  6. Run the resulting executable.
  7. Programs that use the FORTRAN MPI language bindings need to do some additional steps to use the profiling libraries created above. This is because the FORTRAN bindings are contained in a separate shared object from the C bindings.

    The shipped product has a library structure that looks like this:

    	+-------------------------+
    	| libmpi_r.a(mpifort_r.o) |    exports mpi_aaa
    	+-------------------------+    imports MPI_Aaa
                        |     
                        |      
                        |      
    	+-------------------------+ 
    	| libmpi_r.a(mpicore_r.o) |	exports MPI_Aaa 
    	+-------------------------+	exports PMPI_Aaa 
       
       
     
    

    You need to change it into the following structure by rebuilding the mpifort_r.o shared object:

    	+-----------------------------+
    	| libpmpi_r.a(newmpifort_r.o) |    exports mpi_aaa
    	+-----------------------------+    imports MPI_Aaa
                          |            
                          |             
                          |                
    	+------------------------------+   exports MPI_Aaa   
    	| libmyprof_r.a(newmyprof_r.o) |   imports PMPI_Aaa   
    	+------------------------------+     
    		      |
    		      |
    		      |
    	+-------------------------+	exports PMPI_Aaa
    	| libmpi_r.a(mpicore_r.o) |	(exports MPI_Aaa)
    	+-------------------------+
     
    

    To do this, first extract mpifort_r.o from libmpi_r.a:

    ar -xv /usr/lpp/ppe.poe/lib/libmpi_r.a mpifort_r.o
    
  8. Then, construct a script to rebuild mpifort_r.o, using the AIX rtl_enable command:
    rtl_enable -o newmpifort_r.o -s mpifort_r.o -L. -L/usr/lpp/ppe.poe/lib
      -lmyprof_r -lmpi_r -lc_r -lpthreads
    
  9. The rtl_enable command creates a script called mpifort_r.sh and import and export files that reflect the original binding with libmpi_r.a(mpicore_r.o). To break this binding and rebind, remove the reference to the import file:
    sed "s/-bI:mpifort_r.imp//" < mpifort_r.sh > mpifort_r.newsh
    
  10. Make mpifort_r.newsh executable and run it:
    chmod +x mpifort_r.newsh
    mpifort_r.newsh
    
  11. Archive the new shared object:
    ar rv libpmpi_r.a newmpifort_r.o
    
  12. Create a program that uses an MPI function you've profiled. For example, a file called hwinit.f could contain these statements:
     c -------------------------------------
           program  hwinit
           include 'mpif.h'
           integer forterr
     c
           call MPI_INIT(forterr)
     c
     c  Write comments to screen.
     c
           write(6,*)'Hello from task '
     c
           call MPI_FINALIZE(forterr)
     c
           stop
           end
     c
    
  13. Link your FORTRAN executable with the new library:
    mpxlf_r -o hwinit hwinit.f -L. -lpmpi_r
    
  14. Run the resulting executable.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]