⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slog_pstat.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 3 页
字号:
#include <stdio.h>#ifdef HAVE_SLOGCONF_H#include "slog_config.h"#endif#ifdef HAVE_SLOG_WINCONFIG_H#include "slog_winconfig.h"#endif#if defined( STDC_HEADERS ) || defined( HAVE_STDLIB_H )#include <stdlib.h>#endif#if defined( HAVE_UNISTD_H )#include <unistd.h>#endif#include "str_util.h"#include "bswp_fileio.h"#include "slog_fileio.h"#include "slog_header.h"#include "slog_profile.h"#include "slog_pstat.h"/*@C    SLOG_SetPreviewStatisticsSize - Set/Override the default number of bins                                     of the statistics array.  Unmodified Input parameter:. stat_bin_size - the number of bin of the statistics array.  Modified Input parameter :. slog - pointer to the SLOG_STREAM where interval records are stored.  Modified Output parameter :. returned value - integer return status code.  Include file need:  slog_pstat.h.N SLOG_RETURN_STATUS@*/int SLOG_SetPreviewStatisticsSize(       SLOG_STREAM     *slog,                                   const SLOG_uint32      stat_bin_size ){    if ( slog == NULL ) {        fprintf( errfile, __FILE__":SLOG_SetPreviewStatisticsSize() - \n"                          "\t""the input SLOG_STREAM is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_SetPreviewStatisticsSize() - \n"                          "\t""the SLOG_STREAM's Preview Statistics pointer "                          "is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( stat_bin_size <= SLOG_PSTAT_STATSIZE_MAX )        slog->pstat->Nbin = stat_bin_size;    else {        slog->pstat->Nbin = SLOG_PSTAT_STATSIZE_MAX;        fprintf( errfile, __FILE__":SLOG_SetPreviewStatisticsSize() - \n"                          "\t""The input number of bins, "fmt_ui32", is "                          "too big.  Instead the maximum, "fmt_ui32", is "                          "used\n", stat_bin_size, SLOG_PSTAT_STATSIZE_MAX );        fflush( errfile );    }    return SLOG_SUCCESS;}SLOG_pstat_t *SLOG_PSTAT_Create( const SLOG_uint32   stat_set_size ){    SLOG_pstat_t   *slog_pstat;    if ( stat_set_size == 0 ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Create() - \n"                          "Input set size, " fmt_ui32", is zero\n",                          stat_set_size );        fflush( errfile );        return NULL;    }    slog_pstat = ( SLOG_pstat_t * ) malloc( sizeof( SLOG_pstat_t ) );    if ( slog_pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Create() - malloc() fails\n" );        fflush( errfile );        return NULL;    }    /*  Initailize */    slog_pstat->starttime         = SLOG_time_NULL;    slog_pstat->endtime           = SLOG_time_NULL;    slog_pstat->bin_width_in_time = SLOG_time_NULL;    slog_pstat->Nset              = 0;    slog_pstat->Nbin              = stat_set_size;    slog_pstat->sets              = NULL;    slog_pstat->seq_idx_vals      = NULL;    return slog_pstat;}SLOG_pstat_t *SLOG_PSTAT_CreateContent(       SLOG_pstat_t *slog_pstat,                                        const SLOG_uint32   N_stat_set ){    SLOG_uint32     idx;    if ( N_stat_set == 0 ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_CreateContent() - \n"                          "Input No. of sets, "fmt_ui32", is zero\n",                          N_stat_set );        fflush( errfile );        return NULL;    }    if ( slog_pstat == NULL )        slog_pstat = ( SLOG_pstat_t * )  malloc( sizeof( SLOG_pstat_t ) );    if ( slog_pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_CreateContent() - "                          "malloc()/realloc() fails\n" );        fflush( errfile );        return NULL;    }    /*  Initailize */    slog_pstat->Nset = N_stat_set;    slog_pstat->sets = ( SLOG_statset_t ** )                       malloc( slog_pstat->Nset * sizeof( SLOG_statset_t * ) );    if ( slog_pstat->Nset > 0 && slog_pstat->sets == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_CreateContent() - \n"                          "\t""malloc() fails for slog_pstat->sets[]\n" );        fflush( errfile );        return NULL;    }    if ( slog_pstat->Nbin == 0 ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_CreateContent() - \n"                          "\t""Number of bin per set, slog_pstat->Nbin, "                          fmt_ui32", is zero\n", slog_pstat->Nbin );        fflush( errfile );        return NULL;    }    for ( idx = 0; idx < slog_pstat->Nset; idx++ ) {        slog_pstat->sets[ idx ] = SLOG_StatSet_Create( slog_pstat->Nbin );        if ( slog_pstat->sets[ idx ] == NULL ) {            fprintf( errfile, __FILE__":SLOG_PSTAT_CreateContent() - \n"                              "\t""SLOG_StatSet_Create() fails for "                              "slog_pstat->sets["fmt_ui32"]\n", idx );            fflush( errfile );            return NULL;        }    }    slog_pstat->seq_idx_vals = ( SLOG_int32 * )                               malloc( slog_pstat->Nset                                     * sizeof( SLOG_int32 ) );    if ( slog_pstat->Nset > 0 && slog_pstat->seq_idx_vals == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_CreateContent() - \n"                          "\t""malloc() fails for "                          "slog_pstat->seq_idx_vals[]\n" );        fflush( errfile );        return NULL;    }    /*  SLOG_FAIL( -1 ) indicates that it has NOT been used  */    for ( idx = 0; idx < slog_pstat->Nset; idx++ ) {        slog_pstat->seq_idx_vals[ idx ] = SLOG_FAIL;    }    return slog_pstat;}void SLOG_PSTAT_Free( SLOG_pstat_t  *slog_pstat ){    SLOG_uint32  idx;    if ( slog_pstat != NULL ) {        if ( slog_pstat->Nset > 0 && slog_pstat->sets != NULL ) {            for ( idx = 0; idx < slog_pstat->Nset; idx++ )                SLOG_StatSet_Free( slog_pstat->sets[ idx ] );            free( slog_pstat->sets );            slog_pstat->sets = NULL;        }        if ( slog_pstat->Nset > 0 && slog_pstat->seq_idx_vals != NULL ) {            free( slog_pstat->seq_idx_vals );            slog_pstat->seq_idx_vals = NULL;        }        free( slog_pstat );        slog_pstat = NULL;    }}int SLOG_PSTAT_Open( SLOG_STREAM  *slog ){    if ( slog == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Open() - "                          "the input SLOG_STREAM is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    slog->pstat = SLOG_PSTAT_Create( SLOG_PSTAT_STATSIZE_MAX );    if ( slog->pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Open() - "                          "SLOG_PSTAT_Create() fails !\n" );        fflush( errfile );        return SLOG_FAIL;    }    return SLOG_SUCCESS;}int SLOG_PSTAT_Init( SLOG_STREAM  *slog ){    SLOG_pstat_t   *pstat;    SLOG_prof_t    *profile;    SLOG_uint32     pstat_Nset;    SLOG_uint32     pstat_Nbin;    int             idx, count;    int             ierr;    if ( slog == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "the input SLOG_STREAM is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->hdr == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "the pointer to SLOG_hdr_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->prof == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "the pointer to SLOG_prof_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->rec_defs == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "the pointer to SLOG_recdefs_table_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "the pointer to SLOG_pstat_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->prof->Nentries != slog->rec_defs->Nentries ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - \n"                          "\t""Display Profile's Nentries("fmt_ui32") != "                          "Record Definition Table's Nentries("fmt_ui32") !\n",                          slog->prof->Nentries, slog->rec_defs->Nentries );        fflush( errfile );        return SLOG_FAIL;    }    /*  count the WHOLE states in display profile  */    profile  = slog->prof;    pstat_Nset = 0;    for ( idx = 0; idx < (int)profile->Nentries; idx++ ) {        if ( SLOG_IntvlInfo_IsKeyWholeIntvl( &( profile->entries[ idx ] ) ) )            pstat_Nset++;    }    /*          Set the number of the WHOLE states in display profile as         the size of the SLOG_pstat_t    */    slog->pstat = SLOG_PSTAT_CreateContent( slog->pstat,                                            pstat_Nset );    if ( slog->pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "SLOG_PSTAT_CreateContent( Nset="fmt_ui32" ) "                          "fails !\n", slog->prof->Nentries );        fflush( errfile );        return SLOG_FAIL;    }    /*  Update the content of SLOG_hdr_t to both memory and disk  */    slog->hdr->fptr2statistics = slog_ftell( slog->fd );    ierr = SLOG_WriteUpdatedHeader( slog );    if ( ierr != SLOG_SUCCESS ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - "                          "SLOG_WriteUpdatedHeader() fails\n" );        fflush( errfile );        return SLOG_FAIL;    }    /*        Write the Nset=0 and Nbin=0 of SLOG_pstat_t to the disk          to indicate that Nothing has been written to the disk    */    pstat_Nset = 0;    ierr = bswp_fwrite( &( pstat_Nset ),                        sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - \n"                          "\t""Fails at writing the total number of sets "                          "of the Preview Statistics Arrays\n" );        fflush( errfile );        return SLOG_FAIL;    }    pstat_Nbin = 0;    ierr = bswp_fwrite( &( pstat_Nbin ),                        sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Init() - \n"                          "\t""Fails at writing the bin size "                          "of each Preview Statistics Array\n" );        fflush( errfile );        return SLOG_FAIL;    }    /*  Set the properties of SLOG_pstat_t  */    pstat    = slog->pstat;    count = 0;    for ( idx = 0; idx < (int)profile->Nentries; idx++ ) {        if ( SLOG_IntvlInfo_IsKeyWholeIntvl( &( profile->entries[ idx ] ) ) ) {            SLOG_StatSet_SetIntvltype( pstat->sets[ count ],                                       ( profile->entries[ idx ] ).intvltype );            SLOG_StatSet_SetLabel( pstat->sets[ count ],                                   ( profile->entries[ idx ] ).label );            pstat->seq_idx_vals[ count ] = pstat->sets[ count ]->intvltype;            count++;        }    }    return SLOG_SUCCESS;}/*  The following Write() routine can be called multiple times  *//*  But be sure the slog->hdr->fptr2statistics is set  */int SLOG_PSTAT_Write( SLOG_STREAM  *slog ){    filebuf_t    *tmp_fbuf;    SLOG_uint32   expected_bsize;    SLOG_uint32   Nbytes_written;    int           idx;    int           ierr;    if ( slog == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - "                          "the input SLOG_STREAM is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->hdr == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - "                          "the input SLOG_hdr_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - "                          "the input SLOG_pstat_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->pstat->Nset > 0 && slog->pstat->sets == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - \n"                          "\t""SLOG_pstat_t inconsistency detected\n"                          "\t""slog->pstat->Nset = "fmt_ui32" and "                          "slog->pstat->sets[] = NULL\n",                          slog->pstat->Nset );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->hdr->fptr2statistics == SLOG_fptr_NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - \n"                          "\t""the SLOG_STREAM's fptr2statistics points at "                          "SLOG_fptr_NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    /*  Compute the expected byte size of slog->pstat in the file buffer  */    expected_bsize = SLOG_typesz[ ui32 ] * 2                   + SLOG_typesz[  ts  ] * 2                   + SLOG_PSTAT_SizeOfStatSetInFile( slog->pstat->Nbin )                   * slog->pstat->Nset;    /*  Create and initial the file buffer  */    tmp_fbuf = ( filebuf_t * ) fbuf_create( expected_bsize );    if ( tmp_fbuf == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - "                          "fbuf_create() fails!\n" );        fflush( errfile );        return SLOG_FAIL;    }    fbuf_filedesc( tmp_fbuf, slog->fd );    /*  Deposit the content of SLOG_pstat_t to the file buffer  */    Nbytes_written = 0;    ierr = fbuf_deposit( &( slog->pstat->Nset ), SLOG_typesz[ ui32 ],                         1, tmp_fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Write() - Cannot "                          "deposit the Nset to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * SLOG_typesz[ ui32 ];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -