<<

IBM XL for AIX, V16.1 IBM

Migration Guide

Version 16.1

GC27-8052-00

IBM XL Fortran for AIX, V16.1 IBM

Migration Guide

Version 16.1

GC27-8052-00 Note Before using this information and the product it supports, read the information in “Notices” on 15.

First edition This edition applies to IBM XL Fortran for AIX, V16.1 (Program 5765-J14, 5725-C74) and to all subsequent releases and modifications until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. © Copyright IBM Corporation 2018. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents

About this document ...... v Maintaining FORTRAN 77 source and object code 11 Who should read this document...... v Portability of directives ...... 12 How to use this document...... v Common industry extensions that XL Fortran Conventions ...... v supports ...... 13 Related information ...... ix Mixing data types in statements ...... 14 Available help information ...... ix Date and time routines ...... 14 Standards and specifications ...... xi Other libc routines ...... 14 Technical support ...... xi Changing the default sizes of data types.... 14 How to send your comments ...... xii Name conflicts between your procedures and XL Fortran intrinsic procedures ...... 14 Chapter 1. Migrating from earlier Reproducing results from other systems .... 14 versions to the latest version ..... 1 Notices ...... 15 Avoiding or fixing upgrade problems ...... 4 Trademarks ...... 17 Chapter 2. Resolving the compatibility Index ...... 19 issues of IPA object files ...... 9

Chapter 3. programs to XL Fortran...... 11 Outline of the porting process ...... 11

© Copyright IBM Corp. 2018 iii iv XL Fortran: Migration Guide About this document

This document contains migration considerations applicable to IBM® XL Fortran for AIX®, V16.1.

Who should read this document This document is intended for Fortran developers who are to use IBM XL Fortran for AIX, V16.1 to compile programs that were previously compiled on different platforms, by previous releases of XL Fortran, or by other .

How to use this document

While this document covers migration considerations applicable to IBM XL Fortran for AIX, V16.1, it does not include the following topics: v An executive overview of new functions: see the What' New for XL Fortran. v installation: see the XL Fortran Installation Guide. v Overview of XL Fortran features: see the Getting Started with XL Fortran. v Compiler options: see the XL Fortran Compiler Reference for detailed information about the syntax and usage of compiler options. v The Fortran : see the XL Fortran Language Reference for information about the syntax, , and IBM implementation of the Fortran programming language. v Programming topics: see the XL Fortran Optimization and Programming Guide for detailed information about developing applications with XL Fortran, with a focus on program portability and optimization.

Conventions Typographical conventions

The following table shows the typographical conventions used in the IBM XL Fortran for AIX, V16.1 information. Table 1. Typographical conventions Typeface Indicates Example lowercase Invocation commands, executable The compiler provides bold names, and compiler options. invocation commands, xlf, along with several other compiler invocation commands to support various Fortran language levels and compilation environments.

The default file name for the executable program is a.out. italics Parameters or variables whose Make sure that you update the size actual names or values are to be parameter if you return more than supplied by the user. Italics are the size requested. also used to introduce new terms.

© Copyright IBM Corp. 2018 v Table 1. Typographical conventions (continued) Typeface Indicates Example underlining The default setting of a parameter nomaf | maf of a compiler option or directive. monospace Examples of program code, To compile and optimize reference to program code, file myprogram., enter: xlf myprogram.f names, path names, command -O3. strings, or user-defined names. UPPERCASE Fortran programming keywords, The ASSERT directive applies only to bold statements, directives, and intrinsic the DO loop immediately following procedures. Uppercase letters may the directive, and not to any nested also be used to indicate the DO loops. minimum number of characters required to invoke a compiler option/suboption.

Qualifying elements (icons and bracket separators)

In descriptions of language elements, this information uses icons and marked bracket separators to delineate segments of text as follows: Table 2. Qualifying elements Bracket Icon separator text Meaning

F2008 Fortran 2008 The text describes an IBM XL Fortran implementation of begins / the Fortran 2008 standard.1

F2008 Fortran 2008 ends

F2003 Fortran 2003 The text describes an IBM XL Fortran implementation of begins / the Fortran 2003 standard, and it applies to all later standards.1 F2003 Fortran 2003 ends

TS 29113 TS 29113 The text describes an IBM XL Fortran implementation of begins / Technical Specification 29113, referred to as TS 29113.1

TS 29113 TS 29113 ends

IBM IBM extension The text describes a feature that is an IBM XL Fortran begins / extension to the standard language specifications.

IBM IBM extension ends

Note: 1. If the information is marked with a Fortran language standard icon or bracket separators, it applies to this specific Fortran language standard and all later ones. Otherwise, it applies to all Fortran language standards. Syntax diagrams

Throughout this information, diagrams illustrate XL Fortran syntax. This section helps you to interpret and use those diagrams. vi XL Fortran: Migration Guide v Read the syntax diagrams from left to right, from to bottom, following the path of the line. The ►►─── symbol indicates the beginning of a command, directive, or statement. The ───► symbol indicates that the command, directive, or statement syntax is continued on the line. The ►─── symbol indicates that a command, directive, or statement is continued from the previous line. The ───►◄ symbol indicates the end of a command, directive, or statement. Fragments, which are diagrams of syntactical units other than complete commands, directives, or statements, start with the │─── symbol and end with the ───│ symbol. IBM XL Fortran extensions are marked by a number in the syntax diagram with an explanatory note immediately following the diagram. Program units, procedures, constructs, interface blocks and derived-type definitions consist of several individual statements. For such items, a box encloses the syntax representation, and individual syntax diagrams show the required order for the equivalent Fortran statements. v Required items are shown on the horizontal line (the main path):

►► keyword required_argument ►◄ v Optional items are shown below the main path:

►► keyword ►◄ optional_argument

Note: Optional items (not in syntax diagrams) are enclosed by square brackets ([ and ]). For example, [UNIT=]u v If you can choose from two or more items, they are shown vertically, in a stack. If you must choose one of the items, one item of the stack is shown on the main path.

►► keyword required_argument1 ►◄ required_argument2

If choosing one of the items is optional, the entire stack is shown below the main path.

►► keyword ►◄ optional_argument1 optional_argument2 v An arrow returning to the left above the main line (a repeat arrow) indicates that you can make more than one choice from the stacked items or repeat an item. The separator character, if it is other than a blank, is also indicated:

,

►► keyword ▼ repeatable_argument ►◄ v The item that is the default is shown above the main path.

About this document vii default_argument ►► keyword alternate_argument ►◄

v Keywords are shown in nonitalic letters and should be entered exactly as shown. v Variables are shown in italicized lowercase letters. They represent user-supplied names or values. If a variable or user-specified name ends in _list, you can provide a list of these terms separated by commas. v If punctuation marks, parentheses, arithmetic operators, or other such symbols are shown, you must enter them as part of the syntax.

Sample syntax diagram

The following is an example of a syntax diagram with an interpretation:

, (1) ►► EXAMPLE char_constant a ▼ e name_list ►◄ d

Notes: 1 IBM extension

Interpret the diagram as follows: v Enter the keyword EXAMPLE. v EXAMPLE is an IBM extension. v Enter a value for char_constant. v Enter a value for a or b, but not for both. v Optionally, enter a value for c or d. v Enter at least one value for e. If you enter more than one value, you must put a comma between each. v Enter the value of at least one name for name_list. If you enter more than one value, you must put a comma between each. (The _list syntax is equivalent to the previous syntax for e.)

How to read syntax statements

Syntax statements are read from left to right: v Individual required arguments are shown with no special notation. v When you must make a choice between a set of alternatives, they are enclosed by { and } symbols. v Optional arguments are enclosed by [ and ] symbols. v When you can select from a group of choices, they are separated by | characters. v Arguments that you can repeat are followed by ellipses (...). Example of a syntax statement EXAMPLE char_constant {a|b}[c|d]e[,e]... name_list{name_list}...

The following list explains the syntax statement: v Enter the keyword EXAMPLE. viii XL Fortran: Migration Guide v Enter a value for char_constant. v Enter a value for a or b, but not for both. v Optionally, enter a value for c or d. v Enter at least one value for e. If you enter more than one value, you must put a comma between each. v Optionally, enter the value of at least one name for name_list. If you enter more than one value, you must put a comma between each name.

Note: The same example is used in both the syntax-statement and syntax-diagram representations. Examples in this information

The examples in this information, except where otherwise noted, are coded in a simple style that does not try to conserve storage, check for errors, achieve fast performance, or demonstrate all possible methods to achieve a specific result.

The examples for installation information are labelled as either Example or Basic example. Basic examples are intended to document a procedure as it would be performed during a default installation; these need little or no modification. Notes on the terminology used

Some of the terminology in this information is shortened as follows: v The term free source form format often appears as free source form. v The term fixed source form format often appears as fixed source form. v The term XL Fortran often appears as XLF.

Related information The following sections provide related information for XL Fortran: Available help information IBM XL Fortran information

XL Fortran provides product information in the following formats: v Quick Start Guide The Quick Start Guide (quickstart.pdf) is intended to get you started with IBM XL Fortran for AIX, V16.1. It is located by default in the XL Fortran directory and in the \quickstart directory of the installation DVD. v README files README files contain late-breaking information, including changes and corrections to the product information. README files are located by default in the XL Fortran directory and in the root directory of the installation DVD. v Installable man pages Man pages are provided for the compiler invocations and all command-line utilities provided with the product. Instructions for installing and accessing the man pages are provided in the IBM XL Fortran for AIX, V16.1 Installation Guide. v Online product documentation The fully searchable HTML-based documentation is viewable in IBM Knowledge Center at http://www.ibm.com/support/knowledgecenter/SSGH4D_16.1.0/ com..compilers.aix.doc/welcome.html.

About this document ix v PDF documents PDF documents are available on the web at https://www.ibm.com/support/ knowledgecenter/SSGH4D_16.1.0/com.ibm.compilers.aix.doc/ download_pdf.html. The following files comprise the full set of XL Fortran product information.

Note: To ensure that you can access cross-reference links to other XL Fortran PDF documents, download and unzip the .zip file that contains all the product documentation files, or you can download each document into the same directory on your local machine. Table 3. XL Fortran PDF files Document title PDF file name Description What's New for IBM XL whats_new.pdf Provides an executive overview of new Fortran for AIX, V16.1, functions in the IBM XL Fortran for GC27-8054-00 AIX, V16.1 compiler, with new functions categorized according to user benefits. Getting Started with getstart.pdf Contains an introduction to XL Fortran, IBM XL Fortran for AIX, with information about setting up and V16.1, SC27-8056-00 configuring your environment, compiling and linking programs, and troubleshooting compilation errors. IBM XL Fortran for AIX, install.pdf Contains information for installing XL V16.1 Installation Guide, Fortran and configuring your SC27-8062-00 environment for basic compilation and program execution. IBM XL Fortran for AIX, migrate.pdf Contains migration considerations for V16.1 Migration Guide, using XL Fortran to compile programs GC27-8052-00 that were previously compiled on different platforms, by previous releases of XL Fortran, or by other compilers. IBM XL Fortran for AIX, compiler.pdf Contains information about the various V16.1 Compiler compiler options and environment Reference, SC27-8061-00 variables. IBM XL Fortran for AIX, langref.pdf Contains information about the Fortran V16.1 Language programming language as supported Reference, SC27-8063-00 by IBM, including language extensions for portability and conformance to nonproprietary standards, compiler directives and intrinsic procedures. IBM XL Fortran for AIX, proguide.pdf Contains information on advanced V16.1 Optimization and programming topics, such as Programming Guide, application porting, interlanguage calls, SC27-8064-00 floating-point operations, input/output, application optimization and parallelization, and the XL Fortran high-performance libraries.

To read a PDF file, use Adobe Reader. If you do not have Adobe Reader, you can download it (subject to license terms) from the Adobe website at http://www.adobe.com.

More information related to XL Fortran, including IBM Redbooks® publications, white papers, and other articles, is available on the web at http://www.ibm.com/ support/docview.wss?uid=swg27036673. x XL Fortran: Migration Guide For more information about the compiler, see the XL compiler on Power® community at http://ibm.biz/xl-power-compilers. Other IBM information v Parallel Environment for AIX: Operation and Use v The IBM Systems Information Center, at http://publib.boulder.ibm.com/ infocenter/systems/index.jsp?topic=/com.ibm.aix.doc/doc/base/aixparent.htm, is a resource for AIX information. You can find the following books for your specific AIX system: – AIX Commands Reference, Volumes 1 - 6 – Technical Reference: Base and Extensions, Volumes 1 & 2 – AIX National Language Support Guide and Reference – AIX General Programming Concepts: Writing and Debugging Programs – AIX Assembler Language Reference Standards and specifications XL Fortran is designed to support the following standards and specifications. You can refer to these standards and specifications for precise definitions of some of the features found in this information. v American National Standard Programming Language FORTRAN, ANSI X3.9-1978. v American National Standard Programming Language Fortran 90, ANSI X3.198-1992. v ANSI/IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std 754-1985. v Federal (USA) Information Processing Standards Publication Fortran, FIPS PUB 69-1. v Information technology - Programming languages - Fortran, ISO/IEC 1539-1:1991. (This information uses its informal name, Fortran 90.) v Information technology - Programming languages - Fortran - Part 1: Base language, ISO/IEC 1539-1:1997. (This information uses its informal name, Fortran 95.) v Information technology - Programming languages - Fortran - Part 1: Base language, ISO/IEC 1539-1:2004. (This information uses its informal name, Fortran 2003.) v Information technology - Programming languages - Fortran - Part 1: Base language, ISO/IEC 1539-1:2010. (This information uses its informal name, Fortran 2008. We currently provide partial support to this standard.) v Information technology - Further interoperability of Fortran with C, ISO/IEC TS 29113:2012. (This information uses its informal name, Technical specification 29113, referred to as TS 29113. We currently provide partial support to this specification.) v Military Standard Fortran DOD Supplement to ANSI X3.9-1978, MIL-STD-1753 (United States of America, Department of Defense standard). Note that XL Fortran supports only those extensions documented in this standard that have also been subsequently incorporated into the Fortran 90 standard. v OpenMP Application Program Interface Version 3.1 (full support) and OpenMP Application Program Interface Version 4.0 (partial support), available at http://www.openmp.org.

Technical support Additional technical support is available from the XL Fortran Support page at https://www.ibm.com/mysupport/s/topic/0TO0z0000006v5WGAQ/xl- fortran?productId=01t0z000007g71hAAA. This page provides a portal with search capabilities to a large selection of Technotes and other support information.

About this document xi If you have any question on the product, raise it in the XL C, C++, and Fortran Compilers for Power servers community or open a case at https://www.ibm.com/ mysupport/s/topic/0TO0z0000006v5WGAQ/xl- fortran?productId=01t0z000007g71hAAA.

For the latest information about XL Fortran, visit the product information site at https://www.ibm.com/us-en/marketplace/xl-fortran-aix-compiler-power.

How to send your comments Your feedback is important in helping us to provide accurate and high-quality information. If you have any comments or questions about this information or any other XL Fortran information, send [email protected] an email.

Be sure to include the name of the manual, the part number of the manual, the version of XL Fortran, and, if applicable, the specific location of the text you are commenting on (for example, a page number or table number).

xii XL Fortran: Migration Guide Chapter 1. Migrating from earlier versions to the latest version

When you migrate programs from IBM XL Fortran for AIX of earlier versions to the latest version, consider factors including changed compiler options, intrinsic procedures, and environment variables. Changed compiler options -qslmtags In IBM XL Fortran for AIX, V16.1, the option to invoke license usage tracking with SLM Tags logging is changed from -qxflag=slmtags to -qslmtags. -D In IBM XL Fortran for AIX, V16.1, the -D option is updated to define a as in a #define directive. In previous releases, -D was the short form of -qdlines. For more information, see -D in the XL Fortran Compiler Reference. -U In IBM XL Fortran for AIX, V16.1, the -U option is updated to undefine a preprocessor macro defined by the compiler or by the -D compiler option. In previous releases, -U was the short form of -qmixed. For more information, see -U in the XL Fortran Compiler Reference. -qsmp=omp Starting from IBM XL Fortran for AIX, V16.1, the -qsmp=omp option is changed to imply -qdirective=SMP\$:\$OMP:IBMP, which turns on the trigger constants SMP$, $OMP, and IBMP, in addition to the default trigger constant IBM*. In previous releases, when you specify the -qsmp=omp option, the compiler recognizes only the $OMP trigger constant and ignores all trigger constants that you have specified up to that point. Changed intrinsic procedures VEC_CNTLZ(ARG1) In IBM XL Fortran for AIX, V16.1, the data types of the returned value are changed: now the compiler returns the same type as the argument, instead of always returning an unsigned type. When you migrate programs from earlier versions to release versions starting from IBM XL Fortran for AIX, V16.1, this change might cause incompatibility. It is recommended that you change your code according to the new behavior. For more information, see VEC_CNTLZ(ARG1) in the XL Fortran Language Reference. -qsave and -qxlf77=persistent no longer enabled by threadsafe invocation commands

To reduce the risk of thread safety coding issues, the threadsafe invocation commands xlf_r and xlf_r7 no longer list -qsave and -qxlf77=persistent as default options in the compiler . The -qsave option specifies that the

© Copyright IBM Corp. 2018 1 default storage class for local variables is static. The -qxlf77=persistent option saves the address of arguments to subprograms with ENTRY statements in static storage.

If you compile a multithreaded program that has uninitialized local variables with xlf_r or xlf_r7, the program might fail execution. When -qsave is in effect, local variables are stored in static storage and have an initial value of 0. Because xlf_r and xlf_r7 no longer imply -qsave, local variables are stored in automatic storage and do not have a particular initial value.

To ensure proper program behavior, always explicitly initialize the local variables in your program or specify -qinitauto so that the local variables are initialized by the compiler. Alternatively, specify -qsave or -qxlf77=persistent if you are sure that they are safe for your program. If you specify -qsave or -qxlf77=persistent with xlf_r or xlf_r7, a compiler warning message about thread safety is issued. OpenMP threadprivate data compatibility issue between V13.1 and its earlier versions

Starting from XL Fortran V13.1, the implementation of the threadprivate data, that is, OpenMP threadprivate variable, has been improved. The operating system thread local storage is used instead of the runtime implementation. The new implementation might improve performance on some applications.

If you plan to mix the object (.o) files that you have compiled with levels prior to 13.1 with the object files that you compiled with XL Fortran, and the same OpenMP threadprivate variables are referenced in both old and new object files, different implementations might cause incompatibility issues. A link error, a compile time error or other undefined behaviors might occur. To support compatibility with earlier versions, you can use the -qsmp=noostls suboption to switch back to the old implementation. You can recompile the entire program with the default suboption -qsmp=ostls to get the benefit of the new implementation.

If you are not sure whether the object files you have compiled with levels prior to XL Fortran contain any old implementation, you can use the nm command to determine whether you need to use the -qsmp=noostls suboption. The following code is an example that shows how to use the nm command: > nm oldfiles.o ... ._xlGetThStorageBlock U - ._xlGetThValue U - ...

In the preceding example, if _xlGetThStorageBlock or _xlGetThValue is found, this means the object files contain old implementation. In this case, you must use -qsmp=noostls; otherwise, use the default suboption -qsmp=ostls. Binary compatibility issue between V11.1 or V12.1 and its later releases

Because of a change to the signature of a compiler-generated routine, mixing code compiled with XL Fortran V11.1 or V12.1 with code containing parameterized derived types compiled with the latest compiler may require recompiling all the source files. Otherwise, a runtime error will occur if the older code uses certain polymorphic references that can resolve to parameterized derived type objects where a length parameter is involved.

2 XL Fortran: Migration Guide For example, the new application extends a derived type whose declaration was compiled using either XL Fortran V11.1 or XL Fortran V12.1, and the extending type has length derived type parameters, and the new application passes an object that has a dynamic type of the extending type through polymorphism via argument association or function reference to a procedure compiled using XL Fortran V11.1 or XL Fortran V12.1 compiler version.

XL Fortran runtime detects the above issue and halts the execution with the following error message:

XL Fortran detected a mismatch in a compiler-generated routine. If your code contains compilation units compiled with XL Fortran V11.1 or V12.1, recompile them with the latest XL Fortran compiler.

Example of argument association:

V11.1 or V12.1 release V13.1 or later releases module m use m type base integer i type, extends(base) :: child (l) end type integer, len :: l integer :: m(l) contains integer :: n(l) end type sub(arg) class(base) :: arg class(base), allocatable :: b1 class(base), allocatable :: local allocate(child(5) :: b1) call sub(b1) allocate(local, source=arg) end end subroutine end module

The problem is the ALLOCATE statement in 11.1/12.1 code is calling a compiler-generated routine that is compiled using newer releases of XL Fortran compiler other than XL Fortran V11.1 or XL Fortran V12.1 through type bound procedure call. Since the signature of the compiler-generated routine is different between 11.1/12.1 releases and newer releases, module m needs to be recompiled using newer releases of XL Fortran compiler.

Example of function call:

Chapter 1. Migrating from earlier versions to the latest version 3 V11.1 or V12.1 release V13.1 or later releases module m module n type base use m integer i type, extends(base) :: child(l) contains integer, len :: l procedure :: bar => bar_base integer a(l) end type contains type container procedure :: bar => bar_child class(base), allocatable :: b1 end type end type contains contains subroutine bar_child(a) subroutine bar_base(a) class(child(*)) a class(base) a print *, "child" print *, "base" print *, a%a end subroutine end subroutine end module end module

program main function foo() use m use n interface type(container) :: foo function foo() allocate(child(6) :: foo%b1) import end function type(container) :: foo end function end interface type(container) :: c1 c1 = foo() call c1%b1%bar end program

The problem is c1 = foo() in program main is calling a compiler-generated routine that is compiled using newer releases of XL Fortran compiler other than V11.1 or V12.1 through type bound procedure call via function foo. Since the signature of the compiler-generated routine is different between 11.1/12.1 releases and newer releases, program main needs to be recompiled using newer releases of XL Fortran compiler.

Avoiding or fixing upgrade problems Although XL Fortran is generally compatible with FORTRAN 77 programs, there are some changes in XL Fortran and the Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 languages that you should be aware of.

To preserve the behavior of existing compilation environments, the xlf and f77 commands both work as they did in earlier XL Fortran versions wherever possible. As you write entirely new Fortran 90, Fortran 95, Fortran 2003, or Fortran 2008 programs or adapt old programs to avoid potential problems, you can begin using the xlf90, xlf95, xlf2003, and xlf2008 commands, which use Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 conventions for source-code format.

Note that in the following table, you can substitute xlf_r or xlf_r7 for xlf, xlf90_r or xlf90_r7 for xlf90, xlf95_r or xlf95_r7 for xlf95, xlf2003_r for xlf2003, and xlf2008_r for xlf2008. Table 4. Potential problems migrating programs to XL Fortran V16.1. The column on the right shows which problems you can avoid by using the xlf or f77 command. Potential Problem Solution or Workaround xlf Avoids? Compilation Problems

4 XL Fortran: Migration Guide Table 4. Potential problems migrating programs to XL Fortran V16.1 (continued). The column on the right shows which problems you can avoid by using the xlf or f77 command. Potential Problem Solution or Workaround xlf Avoids? New intrinsic procedure names may conflict Use the -qextern option, or with external procedure names. The insert EXTERNAL intrinsic procedure is called instead of the statements to avoid the external procedure. . Consider switching to the Fortran 90 or Fortran 95 procedure if it does what you want. The .XOR. intrinsic operator is not Use the option U recognized. -qxlf77=intxor. Zero-sized objects are not allowed by the Use the xlf90 or xlf95 compiler. command, or use the -qzerosize option with the xlf or f77 command. Performance / Optimization Problems Existing programs or programs linked with Recompile everything. older XL Fortran object files run more slowly or do not show expected performance improvements on new hardware. Programs compiled with -O3 or -qhot Try adding the -qstrict optimization behave differently from those option. unoptimized (different results, exceptions, or compilation messages). The option combination -O and -1 cannot Specify -O and -1 as separate be abbreviated to -O1, to avoid options. misunderstandings. (There are -O2, -O3, -O4, and -O5 optimization levels, but there is no -O1.) Programs that use integer POINTERs Specify the option U produce incorrect results when optimized. -qalias=intptr with the xlf90 or xlf95 command, or use the xlf command. Runtime problems Programs that read to the end of the file To compile existing U and then try to append records without first programs, specify the option executing a BACKSPACE statement do not -qxlf77=softeof with the work correctly. The write requests generate xlf90 or xlf95 command, or error messages. use the xlf command. For new programs, add the BACKSPACE statement before writing past the endfile record. Uninitialized variables are not necessarily Ensure that you explicitly U set to zero, and programs that ran before initialize your variables, use may exceed the user stack limit. The reason the -qsave option with the is that the default storage class is now xlf90 or xlf95 command, or AUTOMATIC, rather than STATIC (an add SAVE statements where implementation choice allowed by the needed in the source. language).

Chapter 1. Migrating from earlier versions to the latest version 5 Table 4. Potential problems migrating programs to XL Fortran V16.1 (continued). The column on the right shows which problems you can avoid by using the xlf or f77 command. Potential Problem Solution or Workaround xlf Avoids? Writing data to some files opened without a Use the option U POSITION= specifier overwrites the files, -qposition=appendold, or instead of appending the data. add POSITION= specifiers where needed. Newly compiled programs are unable to Set the read existing data files containing XLFRTEOPTS to the string NAMELIST data. The reason is that the namelist=old. Fortran 90 and Fortran 95 standards define a namelist format that is different from that The programs that produced used on AIX in the past. the old NAMELIST data must be recompiled. Some I/O statements and edit descriptors When you need to maintain U accept or produce slightly different input compatibility with existing and output. For example, real output now data files, compile with the has a leading zero when appropriate. xlf command. If the incompatibility is due to a The changes to I/O formats are intended to single specific I/O change, be more usable and typical of industry see if the -qxlf77 option has practice, so you should try to use the a suboption for compatibility defaults for any new data you produce. with earlier versions. If so, you can switch to the xlf90 or xlf95 command and use the -qxlf77 option on programs that use the old data files. Numeric results and I/O output are not You may need to generate always exactly identical with XL Fortran existing data files again or to Version 2. Certain implementation details of change any programs that I/O, such as spacing in list-directed output depend on these details. and the meanings of some IOSTAT values, When compatibility with have changed since XL Fortran Version 2. earlier versions is not (This entry is similar to the previous one provided by the -qxlf77 except that these differences are not compiler option or compatible with earlier versions.) XLFRTEOPTS runtime options, there is no way to get the old behavior back. SIGN(A,B) now returns -|A| when B = This behavior conforms with U -0.0. Prior to XL Fortran Version 7.1, it the Fortran 95 standard and returned |A|. is consistent with the IEEE standard for binary floating-point arithmetic. It occurs because the -qxlf90=signedzero option is turned on. Turn it off, or specify a command that does not use this option by default.

6 XL Fortran: Migration Guide Table 4. Potential problems migrating programs to XL Fortran V16.1 (continued). The column on the right shows which problems you can avoid by using the xlf or f77 command. Potential Problem Solution or Workaround xlf Avoids? A minus sign is printed for a negative zero This behavior conforms with U in formatted output. A minus sign is the Fortran 95 standard and printed for negative values that have an occurs because the outputted form of zero (that is, in the case -qxlf90=signedzero option is where trailing non-zero digits are truncated turned on. Turn it off, or from the output so that the resulting output specify a command that does looks like zero). Prior to XL Fortran Version not use this option by 7.1, minus signs were not printed in these default. situations. The handling of IEEE infinity and XL Fortran allows control U not-a-number (NaN) exceptional values has over the display of IEEE changed. By default, XL Fortran displays infinity and NaN exceptional IEEE infinity and NaN exceptional values values. To get the previous based on the command used to compile the behavior, set the . This can result in a mixture of XLFRTEOPTS environment IEEE exceptional value outputs if there are variable to the multiple object files that were compiled naninfoutput=old string. with different options.

Chapter 1. Migrating from earlier versions to the latest version 7 8 XL Fortran: Migration Guide Chapter 2. Resolving the compatibility issues of IPA object files

It is recommended that you use the latest version of the compiler to compile and link the IPA object files to avoid compatibility issues. If any compatibility issues occur, you can try these resolutions. IPA object files that are compiled using earlier versions but are linked by a newer version

When IPA object files that are compiled with earlier versions of compilers are linked by a newer version, errors might occur if the IPA object is compiled by one of the following compilers. v XL Fortran, V15.1.2 or earlier v XL C/C++, V13.1.2 or earlier

Try resolving the compatibility issue using one of the following methods: v Recompile and link your object files with the latest XL compiler if you want to use IPA. v Do not enable the -qipa option. IPA object files that are compiled using newer versions but are linked by an earlier version

If IPA object files that are compiled with newer versions of compilers are linked by an earlier version, errors occur during the link step. You might be able to resolve the issue by recompiling and linking the IPA object files with the latest XL compiler.

For more information, see Interprocedural analysis (IPA) in the XL Fortran Optimization and Programming Guide.

© Copyright IBM Corp. 2018 9 10 XL Fortran: Migration Guide Chapter 3. Porting programs to XL Fortran

XL Fortran provides many features intended to make it easier to take programs that were originally written for other systems or compilers and recompile them with XL Fortran.

Outline of the porting process To port a typical program, you need to identify the nonportable features, modify the source files to remove or work around these features, and compile the program with XL Fortran so you can compare the output with the output from the other system.

The process for porting a typical program looks like this: 1. Identify any nonportable language extensions or features that you used in the original program. Check to see if any of them are supported by XL Fortran: v Language extensions are identified in the XL Fortran Language Reference. v Some extensions require you to specify an XL Fortran compiler option; you can find these options listed in the Portability and migration options table in the XL Fortran Compiler Reference. 2. For any nonportable features that XL Fortran does not support, modify the source files to remove or work around them. 3. Do the same for any implementation-dependent features. For example, if your program relies on exact bit-pattern representation of floating-point values or uses system-specific file names, you may need to change it. 4. Compile the program with XL Fortran. If any compilation problems occur, fix them and recompile and fix any additional errors until the program compiles successfully. 5. Run the XL Fortran-compiled program and compare the output with the output from the other system. If the results are substantially different, there are probably still some implementation-specific features that need to be changed. If the results are only marginally different (for example, if XL Fortran produces a different number of digits of precision or a number differs in the last decimal place), decide whether the difference is significant enough to investigate further. You might be able to fix these differences.

Before porting programs to XL Fortran, read the tips in the following sections so that you know in advance what compatibility features XL Fortran offers.

Maintaining FORTRAN 77 source and object code You can use the compiler of this release to recompile existing FORTRAN 77 programs from XL Fortran Version 2 or later releases.

You can link existing FORTRAN 77 object code from previous version of XL Fortran into programs generated by the compiler of this release. See Linking new objects with existing ones in the XL Fortran Compiler Reference for details.

© Copyright IBM Corp. 2018 11 Portability of directives XL Fortran supports many directives available with other Fortran products. This ensures easy portability between products.

If your code contains trigger_constants other than the defaults in XL Fortran, you can use the -qdirective compiler option to specify them. For instance, if you are porting code contained in a file xx.f, you would use the following command to add the CRAY trigger_constant: xlf95 xx.f -qdirective=mic\$

For fixed source form code, in addition to the ! value for the trigger_head portion of the directive, XL Fortran also supports the trigger_head values C, c, and *.

For more information, see the -qdirective option in the XL Fortran Compiler Reference.

XL Fortran supports a number of programming terms as synonyms to ease the effort of porting code from other Fortran products. Those terms that are supported are dependent on context, as indicated in the following tables: Table 5. PARALLEL DO Clauses and their XL Fortran synonyms PARALLEL DO Clause XL Fortran Synonym LASTLOCAL LASTPRIVATE LOCAL PRIVATE SCHEDULE MP_SCHEDTYPE and CHUNK SAVELAST LASTPRIVATE SHARE SHARED NEW PRIVATE

Table 6. PARALLEL DO scheduling types and their XL Fortran synonyms Scheduling Type XL Fortran Synonym GSS GUIDED INTERLEAVE STATIC(1) INTERLEAVED STATIC(1) INTERLEAVE(n) STATIC(n) INTERLEAVED(n) STATIC(n) SIMPLE STATIC

Table 7. PARALLEL SECTIONS clauses and their XL Fortran synonyms PARALLEL SECTIONS Clause XL Fortran Synonym LOCAL PRIVATE SHARE SHARED NEW PRIVATE

12 XL Fortran: Migration Guide Common industry extensions that XL Fortran supports XL Fortran allows many of the same FORTRAN 77 extensions as other popular compilers.

These extensions include:

Refer to XL Fortran Language Reference Extension Section(s) Typeless constants Typeless literal constants *len length specifiers for types Data types BYTE Byte Long variable names Names Lower case Names Mixing integers and logicals (with -qintlog option) Evaluation of expressions Character-count Q edit descriptor (with -qqcount option) Q (Character Count) Editing Intrinsics for counting set bits in registers and determining POPCNT, POPPAR data-object parity 64-bit data types (INTEGER(8), REAL(8), COMPLEX(8), and Integer Real Complex LOGICAL(8)), including support for default 64-bit types (with Logical -qintsize and -qrealsize options) Integer POINTERs, similar to those supported by CRAY and Sun POINTER(integer) compilers. (XL Fortran integer pointer arithmetic uses increments of one byte, while the increment on CRAY is eight bytes. You may need to multiply pointer increments and decrements by eight to make programs ported from CRAY computers work properly.) Conditional vector (CVMGx) intrinsic functions CVMGx (TSOURCE, FSOURCE, MASK) Date and time service and utility functions (rtc, irtc, jdate, clock_, Service and utility timef, and date) procedures STRUCTURE, UNION, and MAP constructs Structure components, Union and map

Finding nonstandard extensions

XL Fortran supports a number of extensions to various language standards. Many of these extensions are so common that you need to keep in mind, when you port programs to other systems, that not all compilers have them. To find such extensions in your XL Fortran programs before beginning a porting effort, use the -qlanglvl option: $ # -qnoobject stops the compiler after parsing all the source, $ # giving a fast way to check for errors. $ # Look for anything above the base F77 standard. $ xlf -qnoobject -qlanglvl=77std f77prog.f ... $ # Look for anything above the F90 standard. $ xlf90 -qnoobject -qlanglvl=90std use_in_2000.f

Chapter 3. Porting programs to XL Fortran 13 ... $ # Look for anything above the F95 standard. $ xlf95 -qnoobject -qlanglvl=95std use_in_2000.f ... Related reference in the XL Fortran Language Reference

-qlanglvl

-qport Mixing data types in statements The -qctyplss option lets you use character constant expressions in the same places that you use typeless constants. The -qintlog option lets you use integer expressions where you can use logicals, and vice versa. A kind type parameter must not be replaced with a logical constant even if -qintlog is on, nor by a character constant even if -qctyplss is on, nor can it be a typeless constant. Date and time routines Date and time routines, such as dtime, etime, and jdate, are accessible as Fortran . Other libc routines A number of other popular routines from the libc , such as flush, getenv, and system, are also accessible as Fortran subroutines. Changing the default sizes of data types For porting from machines with larger or smaller word sizes, the -qintsize option lets you specify the default size for integers and logicals.The -qrealsize option lets you specify the default size for reals and complex components. Name conflicts between your procedures and XL Fortran intrinsic procedures If you have procedures with the same names as any XL Fortran intrinsic procedures, the program calls the intrinsic procedure. This situation is more likely with the addition of the many new Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 intrinsic procedures.

If you still want to call your procedure, add explicit interfaces, EXTERNAL statements, or PROCEDURE statements for any procedures with conflicting names, or use the -qextern option when compiling. Reproducing results from other systems XL Fortran provides settings through the -qfloat option that help make floating-point results consistent with those from other IEEE systems; this subject is discussed in Duplicating the floating-point results of other systems in the XL Fortran Optimization and Programming Guide.

14 XL Fortran: Migration Guide Notices

Programming interfaces: Intended programming interfaces allow the customer to write programs to obtain the services of IBM XL Fortran for AIX.

This information was developed for products and services offered in the U.S.A. IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service.

IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to:

IBM Director of Licensing IBM Corporation North Castle Drive, MD-NC119 Armonk, NY 10504-1785 U.S.A.

For license inquiries regarding double-byte (DBCS) information, contact the IBM Intellectual Property Department in your country or send inquiries, in writing, to:

Intellectual Property Licensing Legal and Intellectual Property Law IBM Japan, Ltd. 19-21, Nihonbashi-Hakozakicho, Chuo-ku Tokyo 103-8510, Japan

The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you.

This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice.

Any references in this information to non-IBM websites are provided for convenience only and do not in any manner serve as an endorsement of those

© Copyright IBM Corp. 2018 15 websites. The materials at those websites are not part of the materials for this IBM product and use of those websites is at your own risk.

IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you.

Licensees of this program who want to have information about it for the purpose of enabling: (i) the exchange of information between independently created programs and other programs (including this one) and (ii) the mutual use of the information which has been exchanged, should contact:

Intellectual Property Dept. for IBM Corporation 5 Technology Park Drive Westford, MA 01886 U.S.A.

Such information may be available, subject to appropriate terms and conditions, including in some cases, payment of a fee.

The licensed program described in this document and all licensed material available for it are provided by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement or any equivalent agreement between us.

Any performance data contained herein was determined in a controlled environment. Therefore, the results obtained in other operating environments may vary significantly. Some measurements may have been made on development-level systems and there is no guarantee that these measurements will be the same on generally available systems. Furthermore, some measurements may have been estimated through extrapolation. Actual results may vary. Users of this document should verify the applicable data for their specific environment.

Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products.

All statements regarding IBM's future direction or intent are subject to change or withdrawal without notice, and represent goals and objectives only.

This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental.

COPYRIGHT LICENSE:

This information contains sample application programs in source language, which illustrates programming techniques on various operating platforms. You may copy, modify, and distribute these sample programs in any form without payment to IBM, for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating

16 XL Fortran: Migration Guide platform for which the sample programs are written. These examples have not been thoroughly tested under all conditions. IBM, therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. The sample programs are provided “AS IS”, without warranty of any kind. IBM shall not be liable for any damages arising out of your use of the sample programs.

Each copy or any portion of these sample programs or any derivative work, must include a copyright notice as follows:

© (your company name) (year). Portions of this code are derived from IBM Corp. Sample Programs. © Copyright IBM Corp. 1998, 2018.

This software and documentation are based in part on the Fourth Berkeley Software Distribution under license from the Regents of the University of California. We acknowledge the following institution for its role in this product's development: the Electrical Engineering and Computer Sciences Department at the Berkeley campus.

PRIVACY POLICY CONSIDERATIONS:

IBM Software products, including software as a service solutions, (“Software Offerings”) may use cookies or other technologies to collect product usage information, to help improve the end user experience, or to tailor interactions with the end user, or for other purposes. In many cases no personally identifiable information is collected by the Software Offerings. Some of our Software Offerings can help enable you to collect personally identifiable information. If this Software Offering uses cookies to collect personally identifiable information, specific information about this offering's use of cookies is set forth below.

This Software Offering does not use cookies or other technologies to collect personally identifiable information.

If the configurations deployed for this Software Offering provide you as customer the ability to collect personally identifiable information from end users via cookies and other technologies, you should seek your own legal advice about any laws applicable to such data collection, including any requirements for notice and consent.

For more information about the use of various technologies, including cookies, for these purposes, see IBM's Privacy Policy at http://www.ibm.com/privacy and IBM's Online Privacy Statement at http://www.ibm.com/privacy/details in the section entitled “Cookies, Web Beacons and Other Technologies,” and the “IBM Software Products and Software-as-a-Service Privacy Statement” at http://www.ibm.com/software/info/product-privacy.

Trademarks IBM, the IBM logo, and ibm.com are trademarks or registered trademarks of International Business Machines Corp., registered in many jurisdictions worldwide. Other product and service names might be trademarks of IBM or other companies. A current list of IBM trademarks is available on the web at “Copyright and trademark information” at http://www.ibm.com/legal/copytrade.shtml.

Adobe and the Adobe logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, other countries, or both.

Notices 17 is a registered trademark of in the United States and other countries.

18 XL Fortran: Migration Guide Index D directives portability 12

F FORTRAN 77 extensions 13

M migration other systems 11

P portability directives 12 porting programs 11

© Copyright IBM Corp. 2018 19 20 XL Fortran: Migration Guide

IBM®

Product Number: 5765-J14, 5725-C74

Printed in USA

GC27-8052-00