Você está na página 1de 74

Tutorial on programming in PGI Fortran

Li-Pin Juan

Contents
System requirement for GPU accelerating with OpenACC standard .............................................. 4
Linking Intel Math Kernel Library with Portland Visual Fortran ...................................................... 9
Debugging ...................................................................................................................................... 23
Check list when your program shows an error message .......................................................... 23
Inheriting an Existing Fortran Projects Properties ....................................................................... 25
Enabling/Disabling IEEE floating point arithmetic ......................................................................... 25
Create and compile programs ....................................................................................................... 25
The basic operation on PGI Visual Fortran ................................................................................ 25
Compiling on the Microsoft command shell ............................................................................. 27
Creating a new solution (project) .............................................................................................. 28
Functions and subroutines ............................................................................................................ 29
Calling module-defined subroutines ......................................................................................... 29
Calling module-defined subroutines ......................................................................................... 30
Module-defined function misses its own type decalration ....................................................... 31
Part I Passing module-defined functions: an application on taking derivative ......................... 32
Part II Passing vector-valued module-defined functions .......................................................... 34
Part III Passing into a module an external function that is not invoked by the use command 35
PartIV Passing into a module a vector-valued function with dynamic size of image ................ 36
Composition function: an application on solving for steady-state capital stock computation 37
(Obsolete) The use of INTERFACE ............................................................................................. 39
Array, arguments ........................................................................................................................... 42
Dimension declaration .............................................................................................................. 42
The upper bound in the subscript of arrays .............................................................................. 42
Assigning partial matrix to a new array: array indexing ............................................................ 44
Generating one-dimension array with fixed interval ................................................................ 45
Passing array to module-defined functions .............................................................................. 45
Rule in accommodating the dimension for arrays .................................................................... 46

As easy as in Matlab: the array operation ................................................................................. 47


Array allocable: how many colons need I specify ..................................................................... 48
Maxval and Maxloc keeps causing pop-up error messages ...................................................... 48
Selective assignment: array logical assignment ........................................................................ 49
Reshaping 1D array into multi-dimensional one ....................................................................... 50
Data output ................................................................................................................................... 50
Printing the heading of your output file .................................................................................... 50
Output saved into .txt files: typography in Fortran I ................................................................. 50
Accommodating suitable digits for displaying your fraction numbers ..................................... 51
Output saved into .txt files: typography in Fortran II ................................................................ 51
Dynamic filename generating and sequential data saving ....................................................... 53
Printing data series by implied do-loop .................................................................................... 53
A topic relevant to Fotran exporting on Mathematica importing ............................................ 54
Error message, Tips of Fortran programming and others ............................................................. 55
Non-constant expression where constant expression required ............................................... 57
Syntax error at or near : ............................................................................................................ 58
Cannot initialize deferred-shape array pp................................................................................. 59
Missing arguments .................................................................................................................... 60
XXX is use associated and cannot be redeclared ...................................................................... 61
Illegal attempt to redefine symbol gk (a case where more than 50 entries of warning are
caused by a single mistake) ....................................................................................................... 61
Illegal number or type of arguments to reshape keyword argument source ........................ 62
Putting the sign outside the parenthesis .................................................................................. 62
Always have your exponents being of real type ....................................................................... 63
Input arguments should be declared earlier than that of its parental function ....................... 66
Variable declarations always proceeding their value assignment ............................................ 66
USE module statement is necessary for calling subroutines ................................................. 67
The loop counter turns invalid as the loop is accomplished ..................................................... 67
Error: Non-constant expression where constant expression required ..................................... 68
Labeling your do loop for the clarity of your statement ........................................................... 69
Forall statement for high performance fortran......................................................................... 69
Relational operators .................................................................................................................. 70
2

Bypassing potential error message when using Numerical Recipes ......................................... 70


Cautions when translating Fortran 77 to Frotran 90: Amoeba algorithm ................................ 72
Value function iteration goes crazy ........................................................................................... 72
Numerical Recipes in Fortran 77/90.............................................................................................. 73
Not just copy and paste: the setup for use a recipe ................................................................. 73

System requirement for GPU accelerating with OpenACC standard


In this section, you would know the configuration of OpenAcc parallel computing standard in
Portland Visual Fortran 12.10 (PVF 2012), which is integrated with the developer, Microsoft
Visual Studio 2010 (VS 2010) on the operation system Windows 7 service pack 1. Make sure you
follow the installation order listed below:
1. Check whether the operation system you are using is Windows 7 Service pack 1 or later,
to avoid going through the hassles of targeting your processor in the project properties
page in PVF 2012.
2. Install the integrated development environment, VS 2010.
3. Install Microsoft .Net Framework 4.5 Software Development Kit (SDK).
4. Update the driver of your graphic card, say, Nvidia Geforce 610.
5. Install the up-to-date CUDA Toolkit 4.2/4.2 (not earlier or later ) via CUDAs official
website.
6. Install PVF 2012.
Now we are one step away from setting forward our real parallel computing project. To ensure
the set of programs we just installed working properly with OpenACC-based Fortran program,
we should have a test run: You may use the supplementary source code that is stored under the
installation directory of PVF 2012. Here, I take the project, AccelPM_Matmul, for example. 1 I
solely focus on the configuration in PVF 2012s property page. Note that clicking on Apply after
each change.
1. Select Project|Properties. In the left-hand-side navigation pane, skip General and look at
Debugging. In the current project, the compiler would sequentially require you to type
in two arguments, so we may simply in the box next to Application Arguments to pass
the arguments to the application before it is run or debugged. The setting of 1024 and 3
here have nothing to do with the use of OpenACC.
a) Set Optimization to (-fastsse -Mipa=fast, inline).
b) Enable Auto-Parallelization (set it to YES).

C:\Program Files (x86)\Microsoft Visual Studio 10.0\PGI Visual


Fortran\Samples\gpu\AccelPM_Matmul

2. Move to Language on the navigation pane, enable OpenACC Directives by select Yes(acc).
3. Move to Target Processors, choose the model of your CPU, say, AMD Bulldozer.
4. Move to Target Accelerators, select Yes in the box next to target Nvidia Accelerator, and
choose Yes for NVIDIA: Enable Profiling to see the timing information of accelerator
kernel profiling. Set Target Host to YES to generate a unified host+GPU library.
5. Move to Diagnostics, select Yes for revealing Accelerator Information.

6. Click Apply and OK to close the dialog window.

7. Again, on the menu bar, select Tools|Options. On the navigation pane, under Projects
and Solutions, select PVF Directories. Follow the following three figures to add new item
into three application directories. That is,
a. C:\Program Files\PGI\win64\2012\cuda\4.2\bin to Executable files,
b. C:\Program Files\PGI\win64\2012\cuda\4.2\include to Include and module files
c. C:\Program Files\PGI\win64\2012\cuda\4.2\lib64 to library files
8. Click on F5 twice for compiling the codes. (Turning off Anti-virus software in case the
automatic sanding is launched to terminate the execution of the application.)
The supplement source code in the context above could be downloaded from here. A
template with correct Intel Math Kernel Library and CUDA linking for my desktop can be
found here.

Trouble Shooting for the incompatible issue between Visual Studio


2012 and PGI Visual Fortran
run devenv /resetsettings in Visual Studio Command Prompt (authorized with administrative
right)

Linking Intel Math Kernel Library (and MS MPI) with Portland


Visual Fortran
The following configuration is advised by Intel Math Kernel Library Link Line Advisor (link). The
setting may vary with the physical specification of your computer.
Version 1. (without MS MPI and so on)

10

Based on the library list above, we need to complete the linking setup with the following
configuration:
1. Since in this installation example we use PVF2012 as the fortran compiler, a preliminary
step before we proceed to the configuration of linking is to precompile a set of
Fortran95 modules, such as lapack95 and blas95.
a. Launch PVF for VS 2010 cmd (64) on start menu All Programs, with
administrator privilege by right-clicking the icon and selecting Run as
administrator.
b. Change directory to MKL interface for Fortran95 math library: After the
command prompt, type cd <MKL interface directory>, for example, cd
C:\Program Files (x86)\Intel\Composer XE 2013\mkl\interfaces.
c. We need to work on precompiling blas95 and lapack95 sequentially. The order
doesnt matter. Here I only take lapack95 for example. The procedure is similar
for precompiling blas95:
i. You should see a makefile under <mkl dir>\interfaces\lapack95.
ii. Type in the command line, nmake libintel64 install_dir=lapack95
interface=lp64 FC=pgf95, and then hit Enter. (for IVF, use FC=ifort)
iii. The precompiled modules should be generated under the new folder
lapack95 automatically.
d. Apply the same treatment on generating the modules of blas95 (for example,
nmake libintel64 install_dir=blas95 interface=lp64 FC=pgf95. (again, for IVF, use
FC=ifort)
2. Right-click on the solution icon under Solution Explorer, and choose Properties to open
the Property Pages interactive popup window.
3. Over the right-hand-side navigation pane, under Configuration Properties, choose
Fortran|General. In the box next to Additional Include Directories, type in the paths of
header files or precompiled modules. In my PVF compiler under this item, there are two
lines:
C:\Program Files (x86)\Intel\Composer XE 2013\mkl\include
C:\Program Files (x86)\Intel\Composer XE
2013\mkl\interfaces\blas95\blas95\include\intel64\lp64
C:\Program Files (x86)\Intel\Composer XE
2013\mkl\interfaces\lapack95\lapack95\include\intel64\lp64
C:\Program Files\Microsoft HPC Pack 2012\Inc
The first one refers to the folder of MKL header files, such as lapack.f90 or mkl_blas.fi.
The second one contains the modules that are precompiled from Fortran95 interface
libraries, such as blas95.mod and lapack95.mod. Note that if you didnt include the last
two paths, then for a successful compile, we need to add one line command before the
main unit, say, include lapack.f90 if we like to use the module lapack95 in the

11

application. Note that Use lapack95 can be substituted by the command Use
mkl95_lapack.
4. On the navigation pane, select Fortran|Preprocessing to check whether the setting next
to Additional Include Directories has synchronized with that specified in step 2.
5. Dont activate the uses of ACML, IMSL, and MKL, if we want to specify the following
linking to Intel MKL library: on the navigation pane, select linker|General. In my
PVF2012, I add
C:\Program Files (x86)\Intel\Composer XE 2013\mkl\lib\intel64
C:\Program Files (x86)\Intel\Composer XE
2013\mkl\interfaces\blas95\blas95\lib\intel64
C:\Program Files (x86)\Intel\Composer XE
2013\mkl\interfaces\lapack95\lapack95\lib\intel64
C:\Program Files\Microsoft HPC Pack 2012\Lib\amd64
next to Additional Library Directories.
6. The final step is to add the libraries recommended by the Intel Advisor to the box next
to Additional Dependencies under Linker|Input. In my case, they are:
mkl_scalapack_lp64.lib mkl_cdft_core.lib mkl_intel_lp64.lib mkl_core.lib
mkl_pgi_thread.lib mkl_blacs_msmpi_lp64.lib msmpi.lib
C:\Program Files (x86)\Intel\Composer XE
2013\mkl\interfaces\blas95\lib95\lib\intel64\mkl_blas95_lp64.lib
C:\Program Files (x86)\Intel\Composer XE
2013\mkl\interfaces\lapack95\lapack95\lib\intel64\mkl_lapack95_lp64.lib
*Note that the last two paths cannot be omitted.
7. Everything has been done!

12

13

Version 2 (with MS MPI and threading for PGI Visual Fortran)

14

15

16

Linking Intel Math Kernel Library with Intel Visual Fortran


Suppose we want to compile the project on a win32 platform.
Additional Include Directories:
C:\Program Files (x86)\Intel\Composer XE 2013\mkl\include\ia32 2
Additional Library Directories:
C:\Program Files (x86)\Intel\Composer XE 2013\mkl\lib\ia32 3
Additional Dependencies:

2
3

C:\Program Files (x86)\Intel\Composer XE 2013\mkl\include\intel64\lp64 for x64 platform, for example.


For x64 platform, C:\Program Files (x86)\Intel\Composer XE 2013\mkl\lib\intel64

17

mkl_intel_c_dll.lib mkl_intel_thread_dll.lib mkl_core_dll.lib libiomp5md.lib mkl_lapack95.lib


mkl_blas95.lib 4
Link MS MPI.
(1) additional include directories: C:\Program Files\Microsoft HPC Pack 2012\Inc; (2)
additional library directories: C:\Program Files\Microsoft HPC Pack 2012\Lib\amd64
(2) Be sure to enable use Intel Math Kernel Library (Fortran-Libraries): Parallel
(/Qmkl:parallel)
If your

The version for my Visual Studio 2012 IDE contains the following library: mkl_blas95_lp64.lib
mkl_lapack95_lp64.lib mkl_scalapack_lp64.lib mkl_cdft_core.lib mkl_intel_lp64.lib mkl_core.lib
mkl_intel_thread.lib mkl_blacs_msmpi_lp64.lib msmpi.lib

18

19

20

21

22

Debugging
1. choose to compile the program in the Debug, rather than Release, mode; 2. go to
DebugStart debugging, or simply click on the F5 key; 3. play around the placement of
breakpoints. If Fortran were not able to detect the breakpoint of a statement in one specific
code block, just moving the breakpoint up or down a few lines away from the current point
could be a quick workaround.

Check list when your program shows an error message


1) make sure that ALLOCATE and DEALLOCATE is placed at proper place.
Sometimes your variables should be allocated before entering into a FOR or
WHILE loop.
2) make sure the type of variables is consistent with what you intend to define.
3) When breakpoints are not hit as you know the corresponding lines of codes are in
deed executing, (1) make sure to turn off any multi-threading or GPU related
setting in your project. In particular, Solution Explorerright click on the
projectPropertyConfiguration PropertiesFortran. Then make sure not to
choose any thing related to GPU (Cuda, OpenAcc, etc.), optimization and parallel
computing (OpenMP). In Target Processors tab, do not check any box even
though the type of your CPU is shown as one of the alternatives to choose. (2)
delete the debug/release folder under the projects directory. (3) clean and rebuild
the solution.
4) make sure that allocatable variables when declared in module are specified in the
formal form like: REAL(WP), DIMENSION(:), ALLOCATABLE :: var1, rather
than, for example, REAL(WP) :: var1(2). Using the latter form, there would come
a pair of error messages associated with the same mistake saying that Automatic
arrays are not allowed in a MODULE, and Illegal statement in the specification
part of a MODULE.
5) Build and run the program with every new line or so during the process of
completion.
6) Integer variables that serves as loop counter, like i, j, m and n, and are reused
multiple times during the execution have better initialized for each loop construct
in order to avoid the potential interaction between two independent loop calling.
For example, in the following subrtouine,

23

is better than
7) Loot out for the location of the initialization of the loop counter. Wrongly placing
it may keep the counter from increasing properly.

8) If the output file doesnt show up in the designated folder or appear with blank
content, then check whether the statement of format is correct. For example, we
like to write a series of three strings into the file denoted by unit=2.

The data saving demand would fail, if we do not specify correct printout form
with exact three letter a that corresponds to the three strings.

9) Duplicating a module, function and subroutine would lead to message massage


like

24

It happens when copying and pasting existing program unit across modules but
forgetting to deleting the old one.

Inheriting an Existing Fortran Projects Properties


Suppose that the existing project is named, Project-A. The procedure starts with (1) duplicating
the whole folder of Project-A including all its subfolders to whichever directory you like. Rename
the folder and associated files as you like. Next, (2) make sure of deleting both the folders,
Release and Debug, that contain compiled source files, modules, and so on. They are stored
under the directory <new solution/project directory>//x64 by default in my system. Third, (3)
(optional. Give it a try if the compilation after the first two steps doesnt work) remove all the
source files accompanying with the duplicated folder from Solution Explorer, and then add them
back to the project by right-clicking Source Files, and selecting Add|Existing Item from. Lastly, (4)
rebuild the project. Everything has been done now.

Enabling/Disabling IEEE floating point arithmetic

If you want to call the intrinsic function such as isnan(x) or isinf(x) to detect not-a-number or
infinity, then make sure of enabling this function.

Create and compile programs


The basic operation on PGI Visual Fortran

25

Lets walk through how to create a simple program that print Hello World. 5
1. Select File|New|Project from the Visual Studio main menu

2. Then New Project dialog appears. In the Project types window located in the left pane of
the dialog box, expand PGI Visual Fortran, and select Win32. In the Templates window
located in the left pane of the dialog box, select Console Application (32-bit). In the
Name field located at the bottom of the dialog box, type any name you like. Then, click
OK.

3. Now add a print statement to the body of the pop-up window:


5

The subsequent instruction is copied from PGI Visual Fortran Users Guide (Release 2012)

26

Print *, Hello World


The code may look similar to this:

4. To build the solution, from the main menu, select Build|Build Solution. The
View|Output window shows the results of the build.
5. To run the application, select Debug|Start Without Debugging.

Compiling on the Microsoft command shell


Go to StartPGI Visual FortranCommand ShellsPVF 2010 Cmd (64)move to the directory
where the project is stored; the folder should contains the main program and all the subroutines
27

and functions to be compiled and linked. Here is an example. Note that we need to pay
attention to the hierarchy among the subroutines. If A.f90 is called by B.f90, and B.f90 is called
by C.f90, and C.90 is called by the main program, then the order of having these files being
compiled should be arranged as follows: ABCMain Program. Suppose we are working on
the Microsoft command shell. The commands should be entered in order as follows:
1)
2)
3)
4)
5)

$pgf90 -c A.f90
$pgf90 c B.f90
$pgf90 c C.f90
$pgf A.obj B.obj C.ojb main.f90 o main
$main

A detailed example is used below:

Creating a new solution (project)


Now we are creating a project for, say, answering Question 1 of Homework 1 in your Fortran
class:
1. Go to StartAll ProgramsPGI Visual FortranPGI Visual Fortran 2010. Note that if you
want to edit, compile, and then link your source files to generate final executable file, then
the procedure should be to StartAll ProgramsPGI Visual Fortran PVF 2010 Cmd. From
now on, we narrow our focus on the interactive interface provided in the first method.
28

2. Again, FileNewProjectWin32Console Application (32-bit)on the blank next to


Name: type the project name you prefer, for example, hw1q1, and also specifies where the
project should be cached on the blank next to Location:.

Functions and subroutines


Calling module-defined subroutines

29

Calling module-defined subroutines


1. Here is the complete code doing the task in item 1 correctly:

The subroutine is declared as follows:

30

Module-defined function misses its own type decalration

You can see the wrong answer below:

Now we correct the statement by putting the type declaration back to the beginning of
FUNCTION:

31

This is the correct answer:

Part I Passing module-defined functions: an application on taking


derivative
Here is a template for passing FUNCTION to other MODULE

32

The MODULE we use is as follows:

The FUNCTION we use is as follows:


33

Part II Passing vector-valued module-defined functions

Again, the dimension declaration of scalar-valued function is not needed and will pop up an
error message.
34

Part III Passing into a module an external function that is not invoked by
the use command

35

PartIV Passing into a module a vector-valued function with dynamic size


of image

36

Composition function: an application on solving for steady-state capital


stock computation
One method invoking INTERFACE (I think, this method is cumbersome due to the interface
statement):

A much better method in the sense of simplicity is as follows:

37

A complete treatment used for computing steady-state capital stock is as follows:

38

(Obsolete) The use of INTERFACE


1. Suppose we are creating a program that reads in the diameter input and then prints the
answer for corresponding circle area. The program could be broken down into several
programming blocks:

39

a. A MAIN PROGRAM Area that invokes a MODULE Circle (external or internal),


declares INTERFACE, and be in charge of printing outcome on the screen;
b. The MODULE Circle that specifies global parameters, such as Pi;
c. The FUNCTION Area_Circle that is mentioned in INTERFACE.
There is more than one way to produce the outlay of these three statement blocks. Firstly,
we can put them in one single file in the following order: starting with declaring MODULE,
followed by writing the MAIN PROGRAM, and then finishing the single file with the
specification of FUNCTION.

Figure 1 Part A

40

Figure 2 Part B

2. The second way to decompose this single file into independent parts: one for the MAIN
PROGRAM, one for MODULE, and one for FUNCTION. Each file is saved with your preferred
filename associated with the extension filename .f90. The details of the operation in PGI
Fortran is as follows:
a. In the window of Visual Studio (PGI Fortran), go to Solution ExplorerSource
FilesAddNew ItemFree-Format Fortran source file (.f90)In the blank next
to Name:, type Circle (as you prefer) for the MODULE. Copy the statements
between and including MODULE Circle and END MODULE Circle and paste it onto
the new created .90 file.
b. Following the same procedure above, create the .90 files for the MAIN PROGRAM
and the FUNCTION block, respectively: main_program.f90 and Area_Circle.f90.
c. Again, remember to put REAL in the beginning of the line FUNCTION Area_Circle(r)
in the INTERFACE block.
d. Save all the three files, and go to DebugStart without Debugging. A pop-up
window requesting for input should then be shown.
41

3. Note that you can do any other combination between the two extreme outlays mentioned
in 3 and 4: for example, you may only make the MODULE block independent of the single
file mentioned in 3, or only make the FUNCTION block independent of the single one. Either
way would be fine and yields the same outcome for sure.

Array, arguments
Dimension declaration

The upper bound in the subscript of arrays

42

43

Assigning partial matrix to a new array: array indexing

44

Generating one-dimension array with fixed interval

Passing array to module-defined functions


We may pass multi-dimensional arrays to a function, and in turn have the function return a
multi-dimensional array back to the main program. Here is the example where we declare the
function in a MODULE named series routines:

45

Rule in accommodating the dimension for arrays

46

As easy as in Matlab: the array operation

47

Array allocable: how many colons need I specify

Otherwise you would see the following error message: incorrect number of shape specifier

Maxval and Maxloc keeps causing pop-up error messages

48

Selective assignment: array logical assignment

49

Reshaping 1D array into multi-dimensional one

Data output
Printing the heading of your output file

Output saved into .txt files: typography in Fortran I

50

Accommodating suitable digits for displaying your fraction numbers

Output saved into .txt files: typography in Fortran II


1. Here is a template for writing results to files or showing it on the screen:

51

2. A much concise version of writing statement:

52

Dynamic filename generating and sequential data saving

Printing data series by implied do-loop

53

Consider that we want to print an array, say, of size 10-by-10. Normally, we use the for structure
to do the job. Alternatively, we can reduce the multiple-line for-loop statements on a single line.
For example,
PRINT (f4.1),(x(i),i=1,1,9)
PRINT *, (x(i,j),i=1,n) (Note that j is controlled by a hidden for loop )
PRINT (2e12.4), (x(i), y(i), i = 1, 1, 20)
This last command performs the task that orderly prints each row of one-dimension arrays x, y
in the scientific notation with the length of 12 and the precision of 4 decimal spaces. Note that
number 2 is joined to the beginning of e12.4 in order to accommodate two designated spaces
for x(i ) and y (i ).

A topic relevant to Fotran exporting on Mathematica importing

That is, if you save your data as the .txt format without comma separating, then ensure you add
the Table attribute into the IMPORT statement. By the way, if you want to specify the full path
of the target file, just go to InsertFile Pathlook for your file.

54

Error message, Tips of Fortran programming and others


[error] error S0439 : An internal subprogram cannot be passed as
argument
error S0439 : An internal subprogram cannot be passed as argument - fcn2
It is because you can't invoke a contained function of the "main" program by itself.
It is allowed in IVF which supports the standard of Fortran 2008, but not in PGI.

PROGRAM Main
USE ZREAL_INT
REAL(8), DIMENSION(1) :: x, xGuess
REAL(8) :: Fcn1
REAL(8) :: a, b, c, above, below
EXTERNAL :: Fcn1
a=1
b=1
c = -2
above = 7
below = -1
xGuess = 100.
print*,'xGuess',xGuess
!--------------------------------! Fcn1 is an independent function
!--------------------------------CALL D_ZREAL(Fcn1, x, xguess = xGuess)
print*,'x zreal independent',x
!--------------------------------! Fcn2 is a contained function
!--------------------------------CALL D_ZREAL(Fcn2, x, xguess = xGuess)
print*,'x zreal contained',x
CONTAINS
REAL(8) FUNCTION Fcn2(x)
REAL(8) :: x
Fcn2 = a*x**2 + b*x + c
END FUNCTION
END PROGRAM
REAL(8) FUNCTION Fcn1(x)
REAL(8) :: x
Fcn1 = x**2 + x - 2
55

END FUNCTION
While IVF won't issue any error message for the same program code,
PGI will complain that "Your program does not comply with Fortran 2003 rules.
You cannot pass a contained subprogram (Fcn2) as an argument, in Fortran 2003."
You need to revise the declaration of the function Fcn2 by declaring it as a subprogram
in a module.
module mod2
CONTAINS
REAL(8) FUNCTION Fcn2(x)
REAL(8) :: x
Fcn2 = x**2 + x - 2
END FUNCTION
end module

56

[error] An automatic object must not appear in the specification part of


a module; A specification expression object must be a dummy argument,
a Common block object, or an object accessible

turn line 156 to real(wp), dimension(:,:) :: py,pyh. Then, the program can be compiled issuing
no error message.

[Error] unresolved external symbol Rouwenhorst referenced in function


Model_mp_Read_Tran_Matrix

57

Enable the commented out statement. Then the program works.

mt.exe : general error c101008d: Failed to write the updated manifest to


the resource
disable anti-virus program or put visual studio in the list of trusted application to avoid .exe
program is blocked by the anti-virus program.

Non-constant expression where constant expression required


If you forgot to declare the use of the precompiled module---mkl95_precision, you would see
the following error message:

Syntax error at or near :


If you add excessive symbols like ampersand (&) following a coma, then you would encounter
the error message: Syntax error at or near : as shown below.

58

Cannot initialize deferred-shape array pp


If you declare a one-dimension array like the variable pp, as shown below, being assigned values
of specific length but mistakenly being declared as real array of undefined length, then you
would encounter the error message below. To correct the problem is to replace the colon
symbol with 4 that corresponds to the length of the one-dimension array.

59

Missing arguments

60

XXX is use associated and cannot be redeclared


It happens when copying and pasting existing program unit across modules but forgetting
to deleting the old one.

Illegal attempt to redefine symbol gk (a case where more than 50


entries of warning are caused by a single mistake)

61

Illegal number or type of arguments to reshape keyword argument


source
If you mistakenly assign a real one-dimension array values without specifying its length, then
you would see the error message.

Putting the sign outside the parenthesis

62

Always have your exponents being of real type


1. Does it matter to declare an integer as REAL for computing accuracy? Lets do the following
experiment. First we declare it as integer; then we declare it as real.

Then we declare as real:

63

So it does matter to convert integer to real so as to get correct answer as shown in the first
column of the last figure.
Another example is shown below: either to write = 2 ((1)) or = 2 (1. )
that is adding a period after any integer to have computation being in real type.

The wrong answer is:


64

As mentioned above, one of the assignment for is:

The answer is thus correct now.

65

More example:

Input arguments should be declared earlier than that of its parental


function

Variable declarations always proceeding their value assignment

So move the line, e = -1.*[(I,i=1,10)], below the line, real(dp) :: x.

66

USE module statement is necessary for calling subroutines

The wrong message below will show: Unsolved external symbol

The loop counter turns invalid as the loop is accomplished

67

Error: Non-constant expression where constant expression required

68

Labeling your do loop for the clarity of your statement

Forall statement for high performance fortran

69

Relational operators

Bypassing potential error message when using Numerical Recipes


Bypassing potential error message if you think Fortran tends to make a fuss in your code.

70

71

Cautions when translating Fortran 77 to Frotran 90: Amoeba algorithm

Value function iteration goes crazy

72

Numerical Recipes in Fortran 77/90


Not just copy and paste: the setup for use a recipe
Suppose you like to use the algorithm dfpmin provided in Numerical Recipes. First step is to
embed the target subroutine dfpmin in a self-defined module.

Second, to invoke all the ancillary f90 source files of the dfpmin algorithm in the main program,
add the following source files under the same directory of the main program so that during the
time of compiling, the ancillary files can be identified, compiled and linked by the windowsbased PGI Fortran. The ancillary files vary among the algorithm you attempt to use in your main
program. In the current context, we need to add the following source files into the main
program: nrtype.f90, nrutil.f90, nrerror.f90.

73

Therefore, throughout your code, the declaration of variables could use the type defined in
nrtype.f90:

74

Você também pode gostar