PAPI  5.0.1.0
genpapifdef.c
Go to the documentation of this file.
00001 /* This file generates the #defines needed for Fortran examples of PAPI. 
00002    Its output is usually directed to fpapi.h. See Makefile.inc for details. 
00003 */
00004 
00005 /* Modified to produce any of cpp, f77, or f90-style include files.
00006    Accepts an optional command-line argument, one of -c, -f77, or -f90 
00007       (-c default, as in original version of the program).
00008    The Fortran versions are fixed-format (source starts in column 7)
00009    Note: No check is made to ensure that lines don't extend past 72 columns.
00010    Date: 1/26/02 
00011    Rick Kufrin, NCSA/Univ of Illinois <rkufrin@ncsa.uiuc.edu> 
00012 */
00013 
00014 /* Modified to eliminate reliance on libpapi.a.
00015    Now it relies only on a small collection of papi header files.
00016 */
00017 
00018 /* Modified to always generate a symbolic representation for the
00019    maximum negative number. This is a work-around for a compiler
00020    limitation that first showed up on Cray X1 and then spread to
00021    GNU Fortran 4.3.2. Thanks to Jim Rosinski (ORNL) for
00022    identification and testing on this issue.
00023    Date: 06/03/08
00024 */
00025 
00026 #include <stdlib.h>
00027 #include <stdio.h>
00028 
00029 #include <unistd.h>
00030 #include <errno.h>
00031 #include <sys/types.h>
00032 #include <memory.h>
00033 
00034 #include "papi.h"
00035 
00036 #undef NDEBUG
00037 #include <assert.h>
00038 
00039 #define PAPI_EVENTS_IN_DERIVED_EVENT 8  /* to satisfy papi_preset.h */
00040 #include "papi_preset.h"
00041 #include "papi_common_strings.h"
00042 /*
00043     The following array is used to create a series of defines
00044     for use with PAPI in Fortran programs.
00045     The value/name pairs come straight from papi.h. 
00046    They should be manually synchronized with papi.h when changes are made.
00047    The definition of hwi_describe_t is in papi_preset.h
00048 */
00049 
00050 const hwi_describe_t _papi_def[] = {
00051     {PAPI_NULL, "PAPI_NULL", NULL},
00052     {PAPI_VER_CURRENT, "PAPI_VER_CURRENT", NULL},
00053     {PAPI_VERSION, "PAPI_VERSION", NULL},
00054     {PAPI_MAX_PRESET_EVENTS, "PAPI_MAX_PRESET_EVENTS", NULL},
00055 
00056     {PAPI_NOT_INITED, "PAPI_NOT_INITED", NULL},
00057     {PAPI_LOW_LEVEL_INITED, "PAPI_LOW_LEVEL_INITED", NULL},
00058     {PAPI_HIGH_LEVEL_INITED, "PAPI_HIGH_LEVEL_INITED", NULL},
00059     {PAPI_THREAD_LEVEL_INITED, "PAPI_THREAD_LEVEL_INITED", NULL},
00060 
00061     {PAPI_DOM_USER, "PAPI_DOM_USER", NULL},
00062     {PAPI_DOM_KERNEL, "PAPI_DOM_KERNEL", NULL},
00063     {PAPI_DOM_OTHER, "PAPI_DOM_OTHER", NULL},
00064     {PAPI_DOM_SUPERVISOR, "PAPI_DOM_SUPERVISOR", NULL},
00065     {PAPI_DOM_ALL, "PAPI_DOM_ALL", NULL},
00066     {PAPI_DOM_MIN, "PAPI_DOM_MIN", NULL},
00067     {PAPI_DOM_MAX, "PAPI_DOM_MAX", NULL},
00068     {PAPI_DOM_HWSPEC, "PAPI_DOM_HWSPEC", NULL},
00069 
00070     {PAPI_STOPPED, "PAPI_STOPPED", NULL},
00071     {PAPI_RUNNING, "PAPI_RUNNING", NULL},
00072     {PAPI_PAUSED, "PAPI_PAUSED", NULL},
00073     {PAPI_NOT_INIT, "PAPI_NOT_INIT", NULL},
00074     {PAPI_OVERFLOWING, "PAPI_OVERFLOWING", NULL},
00075     {PAPI_PROFILING, "PAPI_PROFILING", NULL},
00076     {PAPI_MULTIPLEXING, "PAPI_MULTIPLEXING", NULL},
00077     {PAPI_ATTACHED, "PAPI_ATTACHED", NULL},
00078     {PAPI_CPU_ATTACHED, "PAPI_CPU_ATTACHED", NULL},
00079 
00080     {PAPI_QUIET, "PAPI_QUIET", NULL},
00081     {PAPI_VERB_ECONT, "PAPI_VERB_ECONT", NULL},
00082     {PAPI_VERB_ESTOP, "PAPI_VERB_ESTOP", NULL},
00083 
00084     {PAPI_MIN_STR_LEN, "PAPI_MIN_STR_LEN", NULL},
00085     {PAPI_HUGE_STR_LEN, "PAPI_HUGE_STR_LEN", NULL},
00086     {PAPI_MAX_STR_LEN, "PAPI_MAX_STR_LEN", NULL},
00087     {PAPI_NUM_ERRORS, "PAPI_NUM_ERRORS", NULL},
00088 
00089     {PAPI_MULTIPLEX_DEFAULT, "PAPI_MULTIPLEX_DEFAULT", NULL},
00090     {PAPI_MULTIPLEX_FORCE_SW, "PAPI_MULTIPLEX_FORCE_SW", NULL},
00091 
00092     {PAPI_DEBUG, "PAPI_DEBUG", NULL},
00093     {PAPI_MULTIPLEX, "PAPI_MULTIPLEX", NULL},
00094     {PAPI_DEFDOM, "PAPI_DEFDOM", NULL},
00095     {PAPI_DOMAIN, "PAPI_DOMAIN", NULL},
00096     {PAPI_DEFGRN, "PAPI_DEFGRN", NULL},
00097     {PAPI_GRANUL, "PAPI_GRANUL", NULL},
00098     {PAPI_DEF_MPX_NS, "PAPI_DEF_MPX_NS", NULL},
00099     //  {PAPI_EDGE_DETECT, "PAPI_EDGE_DETECT", NULL},
00100     //{PAPI_INVERT, "PAPI_INVERT", NULL},
00101     {PAPI_MAX_MPX_CTRS, "PAPI_MAX_MPX_CTRS", NULL},
00102     {PAPI_PROFIL, "PAPI_PROFIL", NULL},
00103     {PAPI_PRELOAD, "PAPI_PRELOAD", NULL},
00104     {PAPI_CLOCKRATE, "PAPI_CLOCKRATE", NULL},
00105     {PAPI_MAX_HWCTRS, "PAPI_MAX_HWCTRS", NULL},
00106     {PAPI_HWINFO, "PAPI_HWINFO", NULL},
00107     {PAPI_EXEINFO, "PAPI_EXEINFO", NULL},
00108     {PAPI_MAX_CPUS, "PAPI_MAX_CPUS", NULL},
00109     {PAPI_ATTACH, "PAPI_ATTACH", NULL},
00110     {PAPI_SHLIBINFO, "PAPI_SHLIBINFO", NULL},
00111     {PAPI_LIB_VERSION, "PAPI_LIB_VERSION", NULL},
00112     {PAPI_COMPONENTINFO, "PAPI_COMPONENTINFO", NULL},
00113     {PAPI_DETACH, "PAPI_DETACH", NULL},
00114 
00115     {PAPI_GRN_THR, "PAPI_GRN_THR", NULL},
00116     {PAPI_GRN_MIN, "PAPI_GRN_MIN", NULL},
00117     {PAPI_GRN_PROC, "PAPI_GRN_PROC", NULL},
00118     {PAPI_GRN_PROCG, "PAPI_GRN_PROCG", NULL},
00119     {PAPI_GRN_SYS, "PAPI_GRN_SYS", NULL},
00120     {PAPI_GRN_SYS_CPU, "PAPI_GRN_SYS_CPU", NULL},
00121     {PAPI_GRN_MAX, "PAPI_GRN_MAX", NULL},
00122 
00123     {PAPI_DERIVED, "PAPI_DERIVED", NULL},
00124 
00125     {PAPI_PROFIL_POSIX, "PAPI_PROFIL_POSIX", NULL},
00126     {PAPI_PROFIL_RANDOM, "PAPI_PROFIL_RANDOM", NULL},
00127     {PAPI_PROFIL_WEIGHTED, "PAPI_PROFIL_WEIGHTED", NULL},
00128     {PAPI_PROFIL_COMPRESS, "PAPI_PROFIL_COMPRESS", NULL},
00129     {PAPI_PROFIL_BUCKET_16, "PAPI_PROFIL_BUCKET_16", NULL},
00130     {PAPI_PROFIL_BUCKET_32, "PAPI_PROFIL_BUCKET_32", NULL},
00131     {PAPI_PROFIL_BUCKET_64, "PAPI_PROFIL_BUCKET_64", NULL},
00132 
00133     {PAPI_USR1_LOCK, "PAPI_USR1_LOCK", NULL},
00134     {PAPI_USR2_LOCK, "PAPI_USR2_LOCK", NULL},
00135     {PAPI_LOCK_USR1, "PAPI_LOCK_USR1", NULL},
00136     {PAPI_LOCK_USR2, "PAPI_LOCK_USR2", NULL},
00137     {PAPI_LOCK_NUM, "PAPI_LOCK_NUM", NULL},
00138 
00139     {PAPI_MH_MAX_LEVELS, "PAPI_MH_MAX_LEVELS", NULL},
00140 
00141     {PAPI_USR1_TLS, "PAPI_USR1_TLS", NULL},
00142     {PAPI_USR2_TLS, "PAPI_USR2_TLS", NULL},
00143     {PAPI_TLS_USR1, "PAPI_TLS_USR1", NULL},
00144     {PAPI_TLS_USR2, "PAPI_TLS_USR2", NULL},
00145     {PAPI_TLS_HIGH_LEVEL, "PAPI_TLS_HIGH_LEVEL", NULL},
00146     {PAPI_TLS_NUM, "PAPI_TLS_NUM", NULL},
00147 
00148 /* Fortran offsets into PAPI_dmem_info_t structure. */
00149     {PAPIF_DMEM_VMSIZE, "PAPIF_DMEM_VMSIZE", NULL},
00150     {PAPIF_DMEM_RESIDENT, "PAPIF_DMEM_RESIDENT", NULL},
00151     {PAPIF_DMEM_HIGH_WATER, "PAPIF_DMEM_HIGH_WATER", NULL},
00152     {PAPIF_DMEM_SHARED, "PAPIF_DMEM_SHARED", NULL},
00153     {PAPIF_DMEM_TEXT, "PAPIF_DMEM_TEXT", NULL},
00154     {PAPIF_DMEM_LIBRARY, "PAPIF_DMEM_LIBRARY", NULL},
00155     {PAPIF_DMEM_HEAP, "PAPIF_DMEM_HEAP", NULL},
00156     {PAPIF_DMEM_LOCKED, "PAPIF_DMEM_LOCKED", NULL},
00157     {PAPIF_DMEM_STACK, "PAPIF_DMEM_STACK", NULL},
00158     {PAPIF_DMEM_PAGESIZE, "PAPIF_DMEM_PAGESIZE", NULL},
00159     {PAPIF_DMEM_MAXVAL, "PAPIF_DMEM_MAXVAL", NULL},
00160 
00161 /* PAPI error defines */
00162  /* 0 */ {PAPI_OK, "PAPI_OK", "No error"},
00163     /* 1 */ {PAPI_EINVAL, "PAPI_EINVAL", "Invalid argument"},
00164     /* 2 */ {PAPI_ENOMEM, "PAPI_ENOMEM", "Insufficient memory"},
00165     /* 3 */ {PAPI_ESYS, "PAPI_ESYS", "A System/C library call failed"},
00166     /* 4 */ {PAPI_ECMP, "PAPI_ECMP", "Not supported by component"},
00167     /* 5 */ {PAPI_ECLOST, "PAPI_ECLOST", "Access to the counters was lost or interrupted"},
00168     /* 6 */ {PAPI_EBUG, "PAPI_EBUG", "Internal error, please send mail to the developers"},
00169     /* 7 */ {PAPI_ENOEVNT, "PAPI_ENOEVNT", "Event does not exist"},
00170     /* 8 */ {PAPI_ECNFLCT, "PAPI_ECNFLCT", "Event exists, but cannot be counted due to hardware resource limits"},
00171     /* 9 */ {PAPI_ENOTRUN, "PAPI_ENOTRUN", "EventSet is currently not running"},
00172     /*10 */ {PAPI_EISRUN, "PAPI_EISRUN", "EventSet is currently counting"},
00173     /*11 */ {PAPI_ENOEVST, "PAPI_ENOEVST", "No such EventSet available"},
00174     /*12 */ {PAPI_ENOTPRESET, "PAPI_ENOTPRESET", "Event in argument is not a valid preset"},
00175     /*13 */ {PAPI_ENOCNTR, "PAPI_ENOCNTR", "Hardware does not support performance counters"},
00176     /*14 */ {PAPI_EMISC, "PAPI_EMISC", "Unknown error code"},
00177     /*15 */ {PAPI_EPERM, "PAPI_EPERM", "Permission level does not permit operation"},
00178     /*16 */ {PAPI_ENOINIT, "PAPI_ENOINIT", "PAPI hasn't been initialized yet"},
00179     /*17 */ {PAPI_ENOCMP, "PAPI_ENOCMP", "Component Index isn't set"},
00180     /*18 */ {PAPI_ENOSUPP, "PAPI_ENOSUPP", "Not supported"},
00181     /*19 */ {PAPI_ENOIMPL, "PAPI_ENOIMPL", "Not implemented"},
00182     /*20 */ {PAPI_EBUF, "PAPI_EBUF", "Buffer size exceeded"},
00183     /*21 */ {PAPI_EINVAL_DOM, "PAPI_EINVAL_DOM", "EventSet domain is not supported for the operation"},
00184     /*22 */ {PAPI_EATTR, "PAPI_EATTR", "Invalid or missing event attributes"},
00185     /*23 */ {PAPI_ECOUNT, "PAPI_ECOUNT", "Too many events or attributes"},
00186     /*24 */ {PAPI_ECOMBO, "PAPI_ECOMBO", "Bad combination of features"}
00187 
00188 };
00189 
00190 
00191 enum deftype_t
00192 { CDEFINE, F77DEFINE, F90DEFINE };
00193 static char comment_char = 'C';
00194 
00195 static void
00196 define_val( const char *val_string, int val, enum deftype_t deftype )
00197 {
00198     char value[20];
00199     /* The Fortran spec defines negative numbers as the negation of a positive number.
00200        Because of that definition, the largest possible 2's complement negative
00201        number cannot be legally expressed in Fortran. Compiler behavior is undefined
00202        and unpredictable on this issue.
00203        Several FORTRAN compilers (GNU Fortran (GCC) > 4.2.3, others?)
00204        will throw errors or warnings for an explicit numeric value of -2147483648,
00205        However, they don't object to an arithmetic evaluation that produces the
00206        desired value. This value happens to be used for the PAPI preset
00207        PAPI_L1_DCM, and PAPI_DOM_HWSPEC. 
00208        The hack below works around that limitation.
00209      */
00210     if ( ( ( unsigned ) val ) == 0x80000000 ) {
00211         sprintf( value, "((-2147483647) - 1)" );
00212     } else {
00213         sprintf( value, "%d", val );
00214     }
00215 
00216     switch ( deftype ) {
00217     case CDEFINE:
00218         printf( "#define %-18s %s\n", val_string, value );
00219         break;
00220     case F77DEFINE:
00221         printf( "      INTEGER %-18s\n      PARAMETER (%s=%s)\n", val_string,
00222                 val_string, value );
00223         break;
00224     case F90DEFINE:
00225         printf( "      INTEGER, PARAMETER :: %-18s = %s\n", val_string, value );
00226         break;
00227     }
00228 }
00229 
00230 static void
00231 createDef( char *title, const hwi_describe_t * descr, int size,
00232            enum deftype_t deftype )
00233 {
00234     int i, j;
00235     /* compute the size of the predefined array */
00236     j = size / sizeof ( hwi_describe_t );
00237 
00238     /* create defines for each line in the general arrays */
00239     printf( "\n%c\n%c  %s\n%c\n\n", comment_char, comment_char, title,
00240             comment_char );
00241     for ( i = 0; i < j; i++ )
00242         define_val( descr[i].name, descr[i].value, deftype );
00243 }
00244 
00245 
00246 int
00247 main( int argc, char **argv )
00248 {
00249     int i;
00250     enum deftype_t deftype = CDEFINE;
00251 
00252     if ( argc > 1 ) {
00253         if ( strcmp( argv[1], "-f77" ) == 0 ) {
00254             deftype = F77DEFINE;
00255             comment_char = '!';
00256         } else if ( strcmp( argv[1], "-f90" ) == 0 ) {
00257             deftype = F90DEFINE;
00258             comment_char = '!';
00259         } else if ( strcmp( argv[1], "-c" ) == 0 ) {
00260             deftype = CDEFINE;
00261             comment_char = 'C';
00262         } else {
00263             fprintf( stderr, "Usage: %s [ -c | -f77 | -f90 ]\n", argv[0] );
00264             exit( 1 );
00265         }
00266     }
00267 
00268     /* print a file header block */
00269     printf
00270         ( "%c\n%c  This file contains defines required by the PAPI Fortran interface.\n",
00271           comment_char, comment_char );
00272     printf( "%c  It is automagically generated by genpapifdef.c\n",
00273             comment_char );
00274     printf( "%c  DO NOT modify its contents and expect the changes to stick.\n",
00275             comment_char );
00276     printf( "%c  Changes MUST be made in genpapifdef.c instead.\n%c\n\n",
00277             comment_char, comment_char );
00278 
00279     /* create defines for the internal array pairs */
00280     createDef( "General purpose defines.", _papi_def, sizeof ( _papi_def ),
00281                deftype );
00282     /* create defines for each member of the PRESET array */
00283     printf( "\n%c\n%c  PAPI preset event values.\n%c\n\n", comment_char,
00284             comment_char, comment_char );
00285 
00286     for ( i = 0; i < PAPI_MAX_PRESET_EVENTS; i++ ) {
00287         if ( _papi_hwi_presets[i].symbol ) {    /* if the event is in the preset table */
00288             define_val( _papi_hwi_presets[i].symbol,
00289                         ( i | PAPI_PRESET_MASK ), deftype );
00290         }
00291     }
00292     exit( 0 );
00293 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines