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

📄 slog_pstat.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 3 页
字号:
                else {  /*  if ( end_idx < beg_idx )  */                    fprintf( errfile, __FILE__                                      ":SLOG_PSTAT_Update() - Warning!! \n"                                      "\t""the computed BIN indexes are "                                      "invalid, beg_bin_idx(%d) < "                                      "end_bin_idx(%d)", beg_idx, end_idx );                    fprintf( errfile, "\t""startime = "fmt_time",  "                                      "endtime = "fmt_time"\n",                                      pstat->starttime, pstat->endtime );                    fprintf( errfile, "\t""irec = " );                    SLOG_Irec_Print( irec, errfile );                    fprintf( errfile, "\n" );                    fflush( errfile );                }            }             else {                fprintf( errfile, __FILE__":SLOG_PSTAT_Update() - Warning!! \n"                                  "\t""the computed SET index to "                                  "SLOG_pstat_t[] is out of range\n " );                fprintf( errfile, "\t""irec = " );                SLOG_Irec_Print( irec, errfile );                fprintf( errfile, "\n" );                fflush( errfile );            }   /*  Endof if ( set_idx != SLOG_FAIL ) */#if defined( NO_ARROW_STAT )        }   /* Endof if ( ! SLOG_global_IsOffDiagRec( lptr->irec->rectype ) ) */#endif    }   /*  for ( lptr = src_bbuf->lhead; lptr != NULL; lptr = lptr->next )  */    return SLOG_SUCCESS;}int SLOG_PSTAT_Close( SLOG_STREAM  *slog ){    int    ierr;    if ( slog == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Close() - "                          "the input SLOG_STREAM is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    if ( slog->pstat == NULL ) {        fprintf( errfile, __FILE__":SLOG_PSTAT_Close() - "                          "the input SLOG_pstat_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }    /*  Write the updated statistics info onto the disk again  */    ierr = SLOG_PSTAT_Write( slog );    if ( ierr != SLOG_SUCCESS ) {        fprintf( errfile, __FILE__":SLOG_CloseOutputStream() - "                          "SLOG_PSTAT_Write( slog ) fails!!\n" );        fflush( errfile );        return SLOG_FAIL;    }    return SLOG_SUCCESS;}SLOG_uint32 SLOG_PSTAT_SizeOfStatSetInFile( const SLOG_uint32  pstat_Nbin  ){    return ( SLOG_typesz[ rtype_t ] + SLOG_typesz[ itype_t ]           + sizeof( SLOG_uint16 )           + SLOG_STRING_LEN * sizeof( char )           + SLOG_typesz[ ui32 ]           + pstat_Nbin      * SLOG_typesz[ sbin ] );}int SLOG_PSTAT_GetSeqIdx( const SLOG_pstat_t     *pstat,                          const SLOG_intvltype_t  in_intvltype ){    int   idx;        for ( idx = 0; idx < (int)pstat->Nset; idx++ ) {        if ( pstat->seq_idx_vals[ idx ] == ( SLOG_int32 ) in_intvltype )            return idx;    }    return SLOG_FAIL;}void SLOG_PSTAT_Print( FILE *outfd, const SLOG_pstat_t  *pstat ){    int   idx;    if ( pstat != NULL ) {        fprintf( outfd, "Collect At : Starttime = "fmt_time", "                        "Endtime = "fmt_time"\n\n",                        pstat->starttime, pstat->endtime );        for ( idx = 0; idx < (int)pstat->Nset; idx++ ) {            fprintf( outfd, "\t""Preview Statistics Set %d : \n", idx );            SLOG_StatSet_Print( outfd, pstat->sets[ idx ] );            fprintf( outfd, "\n" );        }        fprintf( outfd, "\n" );        fflush( outfd );    }    else {        fprintf( outfd, __FILE__":SLOG_PSTAT_Print() - "                        "input pointer SLOG_pstat_t is NULL \n" );        fflush( outfd );    }}/*  -- Component level supporting subroutines  -- */        /* SLOG_StatSet_xxxx methods */SLOG_statset_t *SLOG_StatSet_Create( const SLOG_uint32 stat_set_size ){    SLOG_statset_t   *statset;    SLOG_uint32       ii;    if ( stat_set_size == 0 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_Create() - Input set size, "                          fmt_ui32", is zero\n", stat_set_size );        fflush( errfile );        return NULL;    }    statset = ( SLOG_statset_t * ) malloc ( sizeof( SLOG_statset_t ) );    if ( statset == NULL ) {        fprintf( errfile, __FILE__":SLOG_StatSet_Create() - malloc() fails\n" );        fflush( errfile );        return NULL;    }    statset->Nbin = stat_set_size;    statset->bins = ( SLOG_statbintype * )                    malloc( statset->Nbin * sizeof( SLOG_statbintype ) );    if ( statset->Nbin > 0 && statset->bins == NULL ) {        fprintf( errfile, __FILE__":SLOG_StatSet_Create() - \n"                          "\t""malloc() fails for slog_pstat->bins[]\n" );        fflush( errfile );        return NULL;    }    /*  Initialize  */    statset->rectype    = 0;    statset->intvltype  = 0;    for ( ii = 0; ii < statset->Nbin; ii++ )        statset->bins[ ii ] = ( SLOG_statbintype ) 0.0;    return statset;}void SLOG_StatSet_Free( SLOG_statset_t *statset ){    if ( statset != NULL ) {        if ( statset->Nbin > 0 && statset->bins != NULL ) {            free( statset->bins );            statset->bins = NULL;        }        free( statset );        statset = NULL;    }}int SLOG_StatSet_SetRectype(       SLOG_statset_t   *statset,                             const SLOG_rectype_t    in_rectype ){#if defined( DEBUG )    if ( statset == NULL ) {        fprintf( errfile, __FILE__":SLOG_StatSet_SetRectype() - \n"                          "\t""the input SLOG_statset_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }#endif    statset->rectype = in_rectype;    return SLOG_SUCCESS;}int SLOG_StatSet_SetIntvltype(       SLOG_statset_t   *statset,                               const SLOG_intvltype_t  in_intvltype ){#if defined( DEBUG )    if ( statset == NULL ) {        fprintf( errfile, __FILE__":SLOG_StatSet_SetIntvltype() - \n"                          "\t""the input SLOG_statset_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }#endif    statset->intvltype = in_intvltype;    return SLOG_SUCCESS;}int SLOG_StatSet_SetLabel(       SLOG_statset_t   *statset,                           const char             *in_label ){#if defined( DEBUG )    if ( statset == NULL ) {        fprintf( errfile, __FILE__":SLOG_StatSet_SetLabel() - \n"                          "\t""the input SLOG_statset_t is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }#endif    SLOG_str_ncopy_set( statset->label, in_label, SLOG_STRING_LEN );    return SLOG_SUCCESS;}SLOG_uint32 SLOG_StatSet_ByteSizeInFile( const SLOG_statset_t   *statset ){    return ( SLOG_typesz[ rtype_t ] + SLOG_typesz[ itype_t ]           + sizeof( SLOG_uint16 )           + SLOG_STRING_LEN * sizeof( char )           + SLOG_typesz[ ui32 ]           + statset->Nbin   * SLOG_typesz[ sbin ] );}int SLOG_StatSet_DepositToFbuf( const SLOG_statset_t   *statset,                                      filebuf_t        *fbuf ){    const char          newline = '\n';          SLOG_uint32   Nbytes_written;          SLOG_uint16   label_size;          int           ierr;    Nbytes_written = 0;    ierr = fbuf_deposit( &( statset->rectype ), SLOG_typesz[ rtype_t ],                         1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the RECORD_TYPE to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * SLOG_typesz[ rtype_t ];    ierr = fbuf_deposit( &( statset->intvltype ), SLOG_typesz[ itype_t ],                         1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the INTVL_TYPE to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * SLOG_typesz[ itype_t ];    label_size = SLOG_STRING_LEN;    ierr = fbuf_deposit( &label_size, sizeof( SLOG_uint16 ), 1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the LABEL SIZE to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * sizeof( SLOG_uint16 );    ierr = fbuf_deposit( statset->label, sizeof( char ),                         SLOG_STRING_LEN-1, fbuf );    if ( ierr < SLOG_STRING_LEN-1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the LABEL to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * sizeof( char );    ierr = fbuf_deposit( &newline, sizeof( char ), 1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the newline char to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * sizeof( char );    ierr = fbuf_deposit( &( statset->Nbin ), SLOG_typesz[ ui32 ],                         1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the Nbin to the SLOG filebuffer, "                          fmt_ui32" bytes written so far\n", Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * SLOG_typesz[ ui32 ];    ierr = fbuf_deposit( statset->bins, SLOG_typesz[ sbin ],                         statset->Nbin, fbuf );    if ( ierr < (int)statset->Nbin ) {        fprintf( errfile, __FILE__":SLOG_StatSet_DepositToFbuf() - Cannot "                          "deposit the bins[0.."fmt_ui32"-1] to the SLOG "                          "filebuffer, "fmt_ui32" bytes written so far\n",                          statset->Nbin, Nbytes_written );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_written += ierr * SLOG_typesz[ sbin ];    return Nbytes_written;}int SLOG_StatSet_WithdrawFromFbuf( SLOG_statset_t   *statset,                                   filebuf_t        *fbuf ){          SLOG_uint32   Nbytes_read;          SLOG_uint16   label_size;          int           ierr;    Nbytes_read = 0;    ierr = fbuf_withdraw( &( statset->rectype ), SLOG_typesz[ rtype_t ],                          1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_WithdrawFromFbuf() - Cannot "                          "withdraw the RECORD_TYPE from the SLOG filebuffer, "                          fmt_ui32" bytes read so far\n", Nbytes_read );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_read += ierr * SLOG_typesz[ rtype_t ];    ierr = fbuf_withdraw( &( statset->intvltype ), SLOG_typesz[ itype_t ],                          1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_WithdrawFromFbuf() - Cannot "                          "withdraw the INTVL_TYPE from the SLOG filebuffer, "                          fmt_ui32" bytes read so far\n", Nbytes_read );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_read += ierr * SLOG_typesz[ itype_t ];    ierr = fbuf_withdraw( &label_size, sizeof( SLOG_uint16 ), 1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_WithdrawToFbuf() - Cannot "                          "withdraw the LABEL SIZE from the SLOG filebuffer, "                          fmt_ui32" bytes read so far\n", Nbytes_read );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_read += ierr * sizeof( SLOG_uint16 );    ierr = fbuf_withdraw( statset->label, sizeof( char ),                          label_size, fbuf );    if ( ierr < label_size ) {        fprintf( errfile, __FILE__":SLOG_StatSet_WithdrawFromFbuf() - Cannot "                          "withdraw the LABEL from the SLOG filebuffer, "                          fmt_ui32" bytes read so far\n", Nbytes_read );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_read += ierr * sizeof( char );    ierr = fbuf_withdraw( &( statset->Nbin ), SLOG_typesz[ ui32 ],                          1, fbuf );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_StatSet_WithdrawFromFbuf() - Cannot "                          "withdraw the Nbin from the SLOG filebuffer, "                          fmt_ui32" bytes read so far\n", Nbytes_read );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_read += ierr * SLOG_typesz[ ui32 ];    ierr = fbuf_withdraw( statset->bins, SLOG_typesz[ sbin ],                          statset->Nbin, fbuf );    if ( ierr < (int)statset->Nbin ) {        fprintf( errfile, __FILE__                          ":SLOG_StatSet_WithdrawFromFbuf() - Cannot "                          "withdraw the bins[0.."fmt_ui32"-1] from the SLOG "                          "filebuffer, "fmt_ui32" bytes read so far\n",                          statset->Nbin, Nbytes_read );        fflush( errfile );        return SLOG_FAIL;    }    Nbytes_read += ierr * SLOG_typesz[ sbin ];    return Nbytes_read;}void SLOG_StatSet_Print( FILE *outfd, const SLOG_statset_t  *statset ){    const   int   Nitems_per_line = 5;            int   ii;    fprintf( outfd, "\t""rectype = "fmt_rtype_t",  "                    "intvltype = "fmt_itype_t"\n",                    statset->rectype, statset->intvltype );    fprintf( outfd, "\t""label = %s \n", statset->label );    for ( ii = 0; ii < (int)statset->Nbin; ii++ ) {        fprintf( outfd, fmt_sbin", ", statset->bins[ ii ] );        if ( ii % Nitems_per_line == Nitems_per_line - 1 )            fprintf( outfd, "\n" );    }    fprintf( outfd, "\n" );    fflush( outfd );}

⌨️ 快捷键说明

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