Presentation is loading. Please wait.

Presentation is loading. Please wait.

ENERGY 211 / CME 211 Lecture 29 December 3, 2008.

Similar presentations


Presentation on theme: "ENERGY 211 / CME 211 Lecture 29 December 3, 2008."— Presentation transcript:

1 ENERGY 211 / CME 211 Lecture 29 December 3, 2008

2 Command-line Arguments
main actually accepts arguments: int argc: number of command-line arguments char *argv[]: array of argc C strings containing the arguments First argument, argv[0], is name of the executable Arguments separated by spaces Typically, arguments used to customize execution

3 Calling FORTRAN from C++
Add _ to name of FORTRAN function Pass addresses of non-array arguments Remember that matrices are stored in column order in FORTRAN, so be sure to keep code consistent FORTRAN functions must be declared like other external functions Precede declaration with extern "C" so simple C naming convention used

4 Linking FORTRAN with C++
Use gfortran –c to compile each FORTRAN source file On elaine or other workstations, can also use f90, but that is not a GNU compiler and doesn't always work with C++ code compiled with g++ Use g++ -c to compile each C++ source file Use g++ to link all .o files

5 Calling C++ from FORTRAN
Functions called by FORTRAN code must accept pointers to non-array arguments, because FORTRAN passes by reference In C++ code (as opposed to C), precede function declarations with extern "C" End function names with _ Remember matrix storage conventions!

6 On the FORTRAN side Leave out _ at end of C/C++ function names, FORTRAN compiler adds them automatically Declare functions as external, like other external FORTRAN routines Pass arguments normally (ignore that they are pointers on the C/C++ side) A double in C++ corresponds to type double precision in FORTRAN

7 Linking C++ with FORTRAN
Use gfortran –c to compile each FORTRAN source file Use g++ -c to compile each C++ source file Use gfortran to link all .o files If C++ code uses any Standard Library code, must explicitly link with it Library name is libstdc++.so

8 Next Time Mop-up! Final project discussion
Loading dynamic libraries in UNIX private and friend classes More overloading


Download ppt "ENERGY 211 / CME 211 Lecture 29 December 3, 2008."

Similar presentations


Ads by Google