Calling Interfaces
From PAPIDocs
Jump to: navigation, search

C AND FORTRAN CALLING INTERFACES

PAPI is written in C. The function calls in the C interface are defined in the header file, papi.h and consist of the following form:

 
<returned data type> PAPI_''function_name''(''arg1, arg2'',…)
 

The function calls in the Fortran interface are defined in the header file, fpapi.h and consist of the following form:

 
PAPIF_''function_name''(''arg1, arg2'', …, check) 
 

As you can see, the C function calls have equivalent Fortran function calls (PAPI_<call> becomes PAPIF_<call>). This is generally true for most function calls, except for the functions that return C pointers to structures, such as PAPI_get_opt and PAPI_get_executable_info, which are either not implemented in the Fortran interface, or implemented with different calling semantics. In the function calls of the Fortran interface, the return code of the corresponding C routine is returned in the argument,'check'.

For most architectures, the following relation holds between the pseudo-types listed and Fortran variable types:

Pseudo-type Fortran type Description
C_INT INTEGER Default Integer type
C_FLOAT REAL Default Real type
C_LONG_LONG INTEGER*8 Extended size integer
C_STRING CHARACTER*(PAPI_MAX_STR_LEN) Fortran string
C_INT FUNCTION EXTERNAL INTEGER FUNCTION Fortran function returning integer result

Array arguments must be of sufficient size to hold the input/output from/to the subroutine for predictable behavior. The array length is indicated either by the accompanying argument or by internal PAPI definitions.

Subroutines accepting C_STRING as an argument are on most implementations capable of reading the character string length as provided by Fortran. In these implementations, the string is truncated or space padded as necessary. For other implementations, the length of the character array is assumed to be of sufficient size. No character string longer than PAPI_MAX_STR_LEN is returned by the PAPIF interface.