beautypg.com

Notes, Fortran code example – HP XC System 3.x Software User Manual

Page 68

background image

} else {
perror("popen()");
}
}
}
}

Notes

Note the following items:

The first if block terminates an existing label process. This block provides a locking
mechanism and is included for applications that use multiple phases or start and stop labels
multiple times during execution.

You can construct the label name using environment variable values, numeric function
arguments (such as problem size or phase number), or text function arguments (such as
data set name or phase name).

In this example, the HPCPI_LABEL environment variable controls the use of HPCPI labels
in the application. If the HPCPI_LABEL environment variable is not set, no HPCPI label is
started. The HPCPI_LABEL environment variable also provides the label name.

The do_hpcpi_label() function only stops or starts the HPCPI label. The action (start or
stop) is controlled by the value of the start argument passed to the function. This enables
you to declare the labeler as a function-static variable.

Placing the code that starts hpcpictl label and related code in a separate function
do_hpcpi_label()

) makes the invoking code cleaner.

In the application, a start call (do_hpcpi_label(1)) is inserted in the main code just prior
to the timing run, and a stop call (do_hpcpi_label(0)) just after the timing run.

Fortran Code Example

The following is a C-language Fortran-callable routine to label the phases of an application. It
uses a traditional convention for name manipulation and executing C code from Fortran; you
might need to adjust it for some compiler environments.

#include
#include
:
:
void
notephase_(char name[], int namelen)
{
static int manage_labels = -1;
static FILE * labeler = NULL;
if (labeler) {
pclose(labeler);
labeler = NULL;
}
if (manage_labels < 0)
manage_labels = (getenv("MANAGE_HPCPI_LABELS") != NULL);
if (manage_labels && name && (namelen > 0)) {
char command[1024];
const char * hpcpictl = "/opt/hpcpi/bin/hpcpictl";
sprintf(command, "%s label %.*s -pid %d /bin/cat",
hpcpictl, namelen, name, getpid());
labeler = popen(command, "w");
sleep(1);
}
}

68

Using HPCPI Labels