| Parallel Scientific Computing in C++ and MPI : A Seamless Approach to Parallel Algorithms and their Implementation - Compilation Guide |
|
Page 12 of 12
Compilation GuideThis directory (/CODE) contains the following:
A Note Concerning Compilers, Compilation and NavigationIn the writing of this software, every attempt has been made to conform to the ANSI C++ standard. Software development and testing were performed on an Intel processor based PC running Redhat Linux version 8.0. Compilation was accomplished using the GNU gcc 3.2 compiler. Although some compilation tests were accomplished using native compilers under AIX, IRIX and SunOS operating systems, proper compilation and execution are not guaranteed. No compilation tests were performed under the Microsoft Windows or Macintosh operating systems. Navigation of this CD has been tested under both the Linux and the Microsoft Windows operating systems. A Note to Macintosh Users: Mac OS X is required for properly navigating this CD. Prior versions of the Mac operating system appear to interpret the filenames on this CD using the 8.3 character convention, and hence filenames with the first eight characters being identical are not distinguishable. Compilation of SCmathlib for Serial Programs(1)Enter the directory CODE. If you do a directory listing, you should see a file called Makefile. After hitting return, you should see something similar (depending on what system you are running on) to the following: g++ -O3 -c SCmathlib.cpp (3) If you now do a directory listing, you should see that the file libSCmathlib.a has been created. Compilation of SCmathlib for Parallel Programs(1) Enter the directory CODE. If you do a directory listing, you should see a file called Makefile.(2) type: gmake MPISRC=1 After hitting return, you should see something similar (depending on what system you are running on) to the following: g++ -O3 -DMPISRC -c SCmathlib.cpp (3) If you now do a directory listing, you should see that the file libSCmathlibP.a has been created. Serial Program Compilation Guide (from Appendix A)For the purposes of this compilation example, we will assume that we are using the GNU g++ compiler to compile a C++ program we have written contained within the file myprog.cpp. In the following examples, the argument following the '-o' flag designates the file name to be used for the output. If no '-o' option is specified, most compilers default to using the name ''a.out''. We now present several different programming scenarios:
g++ -o myprog myprog.cpp g++ -o myprog myprog.cpp -lmath g++ -o myprog myprog.cpp -I/users/kirby/includes -L/users/kirby/libs The string following the `-I' flag designates the location of the user-defined header files to be included. The string following the `-L' flag designates the location of the user-defined libraries to be included. The string `-lSCmathlib' links the program with the user-defined library we created, and the string `-lmath' links the program with the system math library corresponding to math.h Parallel Program Compilation Guide (from Appendix B)For the purposes of this compilation example, we will assume that we are using the GNU g++ compiler to compile a C++ program we have written contained within the file myprog.cpp. We will also assume that the machine on which you are trying to compile is a parallel machine with some version of MPI installed. You will need to contact your system administrator to find out the exact version of MPI that is available and the paths on your local architecture. In the following examples, the argument following the `-o' flag designates the file name to be used for the output. If no `-o' option is specified, most compilers default to using the name ``a.out''. We now present several different programming scenarios:
g++ -o myprog myprog.cpp -lmpi g++ -o myprog myprog.cpp -lmath -lmpi g++ -o myprog myprog.cpp -I/users/kirby/includes -L/users/kirby/libs The string following the `-I' flag designates the location of the user-defined header files to be included. The string following the `-L' flag designates the location of the user-defined libraries to be included. The string `-lSCmathlib' links the program with the user-defined library we created, and the string `-lmath' links the program with the system math library corresponding to math.h. The string `-lmpi' links the MPI libraries. You will need to contact your system administrator to verify the exact command used on your computing architecture to run an MPI program. In general, most architectures execute MPI programs in a fashion similar to the following: mpirun -np 4 myprog where mpirun is a special program used for starting execution on the parallel machine, `-np 4' indicates the number of processes requested, and myprog denotes the program executable compiled as discussed above. A Note Concerning MakefilesFor those new to the Unix programming environment, addition information concerning makefiles can be found both on the web and in many good books, one of which is Managing Projects with make by Andrew Oram and Steve Talbott. Another useful source of information for gmake (GNU make, which is used above) and g++ (the GNU C++ compiler) is the GNU website, www.gnu.org. A Note Concerning File PermissionsDepending on how your system is configured, it may be necessary to change the directory and file permissions in order to compile within the CODE directory. If you do encounter permission problems, do the following: change directory to the parent directory of the CODE directory (from which, under Unix, you can see the directory CODE by doing an 'ls'). Type the expression within quotes: "chmod -R 755 CODE". This will set the directory CODE and all files and subdirectories to be owner-RWX (read/write/execute) and group and world RX (read/execute). |