- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
A friend of mine gives me its own code as an example of MPI in fortran.
In the code there are some flag as:
#ifdef PARALLEL
what are they?
How can I compile the code?
thanks a lot
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
These are preprocessor symbols.
You can compile your program by adding the "-fpp" switch to your command line. That will invoke the Fortran preprocessor (aka, fpp) before calling the compiler.
On Linux and OS X that will happen automatically if the source program has an uppercased extension name, such as foo.F90.
--Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot,
so I have to compile with -fpp, for example
mpif90 test.f90 -fpp
Do I have to put something more as the number of processor?
Thanks again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The #ifdef you show above indicates that there are sections of the code which are to be conditionally compiled. This works by adding defines to the compile line to include or exclude certain functionality in the source code which is then passed to the compiler. So compilation works in two steps when there are #ifdef or #define etc symbols: 1) preprocessing and 2) compiling the output from the preprocessor. Adding -fpp to the compile command say to do the preprocessing, and then immediately compile the result. It might be informative to play around with fpp to see the results output from the preprocessed source code.
For example, it looks like the code has the ability to conditionally include or exclude parallelism. To conditionally include the code sections enabling parallelism you would need to define PARALLEL. This can be done by including a line like `#define PARALLEL` in the source code, or by adding a define to the preprocessor flags `-DPARALLEL`. So to see what’s going on, you could try something like
fpp -DPARALLEL inputfile.F90 > inputfile.f90
and then compare the two.
You need to consult with the code author about what the available options and macros are and when and how to use them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
dear,
indeed in my code there is for example:
USE mod_heat2D IMPLICIT NONE #ifdef PARALLEL INCLUDE 'mpif.h' #endif
I do not understand how I have to compile
Thanks a lot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As I tried to explain in the previous comment, you should probably be asking the person who gave you the code how to compile it. All we can do, without seeing the entire code, is provided guesses based on what you have told us so far.
If you want to compile it with MPI support, you will need to add `-fpp -DPARALLEL` to the compiler switches. Also, you should be using an MPI wrapper script (usually called mpif90) to do the compilation. So try something like:
mpif90 -fpp -DPARALLEL test.f90
Also, please note that the usual naming convention is for file extension to use uppercase ‘F’ instead of lower case for files that require preprocessing—files with #ifdef etc in them. So I would rename test.f90 to test.F90, or urge the person who gave you the code to do so themselves.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear I.,
Thanks a lot. It works now.
I would like to ask another things about debugging but it is better to start a new Topic.
Thanks a lot
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page