src/tio_malloc.c
/*
 * Print report when process terminates.
 */
Print report when process terminates.
Print report when process terminates .
static void exit_stats(void)
{
  char buffer[8192];    
  char *out = buffer;   
#if defined(__QK_USER__)
  int rank = _my_rank;
#elif defined(__crayx1)
  extern unsigned int _dm_my_pe;
  int rank = _dm_my_pe;
#elif defined(ibm)
  char *env_rank = getenv("MP_CHILD");
  int rank;
  if (env_rank != NULL) {
    rank = atoi(env_rank);
  }
  else {
    rank = 0;
  }
#else
  char *env_rank = getenv("MPIRUN_RANK");
  int rank;
  if (env_rank != NULL) {
    rank = atoi(env_rank);
  }
  else {
    rank = 0;
  }
#endif
  if (disable) {
    return;
  }
  if (rank >= 0) {
    out += sprintf(out, "PE %d: ", rank);
  }
  out += sprintf(out, "Heap allocation statistics:\n");
  if (heap_error) {
    out += sprintf(out, "Heap allocation statistics failed.\n");
    out += sprintf(out, "No statistics will be reported.\n");
  }
  else if (0 == sumcount) {
    out += sprintf(out, "No heap allocation occured.\n");
  }
  else {
    double max_mb    = (double) maxmem / 1024 / 1024;
    long   avg_block = (double) summem / sumcount;
    out += sprintf(out, "%12.6f megabytes maximum heap allocation.\n", (float)max_mb);
    out += sprintf(out, "%12lld blocks allocated maximum.\n", (long long int)maxcount);
    out += sprintf(out, "%12lld blocks allocated total.\n",   (long long int)sumcount);
    out += sprintf(out, "%12lld bytes average block size.\n", (long long int)avg_block);
  }
  write(2, buffer, strlen(buffer));   
  if (dump) {
    size_t i;
    out = buffer;
    if (rank >= 0) {
      out += sprintf(out, "\nPE %d: ", rank);
    }
    out += sprintf(out, "Allocated memory:\n");
    write(2, buffer, strlen(buffer));
    for (i=0; i<heap_count; ++i) {
      if (heap_list[i].p != NULL) {
        out = buffer;
        out += sprintf(out, "[%06d] %12lld bytes allocated - %#012lx ",
                       (int)i, (long long int)heap_list[i].size, (long unsigned int)heap_list[i].p);
#ifdef _TYPHIO_MEMORY_DEBUG
        out += snprintf(out, SUBNAME_LEN, "%s", heap_list[i].subname);
        out += sprintf(out, " (%d)\n", heap_list[i].line);
#else
        out += sprintf(out, " \n");
#endif
        write(2, buffer, strlen(buffer));
      }
    }
    if (heap_list != NULL) {
      free (heap_list);
    }
    (void) sprintf(buffer, "   -- Done\n");
    write(2, buffer, strlen(buffer));
  }
  return;
}
static void exit_stats ( void ) { char buffer [ 8192 ] ; char * out = buffer ; #if defined ( __QK_USER__ ) int rank = _my_rank ; #elif defined ( __crayx1 ) extern unsigned int _dm_my_pe ; int rank = _dm_my_pe ; #elif defined ( ibm ) char * env_rank = getenv ( " " ) ; int rank ; if ( env_rank != NULL ) { rank = atoi ( env_rank ) ; } else { rank = 0 ; } #else char * env_rank = getenv ( " " ) ; int rank ; if ( env_rank != NULL ) { rank = atoi ( env_rank ) ; } else { rank = 0 ; } #endif if ( disable ) { return ; } if ( rank >= 0 ) { out += sprintf ( out , " " , rank ) ; } out += sprintf ( out , " \n " ) ; if ( heap_error ) { out += sprintf ( out , " \n " ) ; out += sprintf ( out , " \n " ) ; } else if ( 0 == sumcount ) { out += sprintf ( out , " \n " ) ; } else { double max_mb = ( double ) maxmem / 1024 / 1024 ; long avg_block = ( double ) summem / sumcount ; out += sprintf ( out , " \n " , ( float ) max_mb ) ; out += sprintf ( out , " \n " , ( long long int ) maxcount ) ; out += sprintf ( out , " \n " , ( long long int ) sumcount ) ; out += sprintf ( out , " \n " , ( long long int ) avg_block ) ; } write ( 2 , buffer , strlen ( buffer ) ) ; if ( dump ) { size_t i ; out = buffer ; if ( rank >= 0 ) { out += sprintf ( out , " \n " , rank ) ; } out += sprintf ( out , " \n " ) ; write ( 2 , buffer , strlen ( buffer ) ) ; for ( i = 0 ; i < heap_count ; ++ i ) { if ( heap_list [ i ] . p != NULL ) { out = buffer ; out += sprintf ( out , " " , ( int ) i , ( long long int ) heap_list [ i ] . size , ( long unsigned int ) heap_list [ i ] . p ) ; #ifdef _TYPHIO_MEMORY_DEBUG out += snprintf ( out , SUBNAME_LEN , " " , heap_list [ i ] . subname ) ; out += sprintf ( out , " \n " , heap_list [ i ] . line ) ; #else out += sprintf ( out , " \n " ) ; #endif write ( 2 , buffer , strlen ( buffer ) ) ; } } if ( heap_list != NULL ) { free ( heap_list ) ; } ( void ) sprintf ( buffer , " \n " ) ; write ( 2 , buffer , strlen ( buffer ) ) ; } return ; }
Print report when process terminates.
Print report when process terminates .
/* printing output buffer         */ /* pointer into the output buffer */ /* Catamount Cray XT3 */ /* Cray X1 */ /* IBM AIX */ /* MPICH */ /* unbuffered write to file descriptor 2 = stderr */ /* out += sprintf(out, "%64s (%d)\n", heap_list[i].subname, heap_list[i].line); */