Using Shared Libraries


Up: Details Next: File System Issues Previous: C++

Shared libraries can help reduce the size of an executable. This is particularly valuable on clusters of workstations, where the executable must normally be copied over a network to each machine that is to execute the parallel program. However, there are some practical problems in using shared libraries; this section discusses some of them and how to solve most of those problems. Currently, shared libraries are not supported from C++.

In order to build shared libraries for mpich, you must have configured and built mpich with the --enable-sharedlib option. Because each Unix system and in fact each compiler uses a different and often incompatible set of options for creating shared objects and libraries, mpich may not be able to determine the correct options. Currently, mpich understands Solaris, GNU gcc (on most platforms, including Linux and Solaris), and IRIX. Information on building shared libraries on other platforms should be sent to [email protected].

Once the shared libraries are built, you must tell the mpich compilation and linking commands to use shared libraries (the reason that shared libraries are not the default will become clear below). You can do this either with the command line option -shlib or by setting the environment variable MPICH_USE_SHLIB to yes. For example,

    mpicc -o cpi -shlib cpi.c 
or
    setenv MPICH_USE_SHLIB yes 
    mpicc -o cpi cpi.c 
Using the environment variable MPICH_USE_SHLIB allows you to control whether shared libraries are used without changing the compilation commands; this can be very useful for projects that use makefiles.

Running a program built with shared libraries can be tricky. If you have trouble, particular if programs will either not start or start and issue error messages about missing libraries, see Section Troubleshooting Shared Libraries .



Up: Details Next: File System Issues Previous: C++