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

📄 slog_profile.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 4 页
字号:
                      "in the Display Profile Table\n",                      intvltype, bebit_0, bebit_1 );    fflush( errfile );    return NULL;}static int SLOG_IntvlInfo_CompareKey( const SLOG_intvlinfo_t *info1,                                      const SLOG_intvlinfo_t *info2 ){    int order1, order2;    if ( info1->intvltype < info2->intvltype )        return -1;    else if ( info1->intvltype == info2->intvltype ) {        order1 = SLOG_bebits_GetOrder( info1->bebits );        order2 = SLOG_bebits_GetOrder( info2->bebits );        if ( order1 < order2 )            return -1;        else if ( order1 == order2 )            return 0;        else            return 1;    }    else        return 1;}static int SLOG_IntvlInfo_CompareKeyFn( const void *info1, const void *info2 ){    return( SLOG_IntvlInfo_CompareKey( (SLOG_intvlinfo_t *) info1,                                       (SLOG_intvlinfo_t *) info2 ) );}void SLOG_PROF_SortTable( SLOG_prof_t  *profile ){    qsort( profile->entries, profile->Nentries, sizeof( SLOG_intvlinfo_t ),           &SLOG_IntvlInfo_CompareKeyFn );}int SLOG_PROF_IsBebitIntvlsConsistent( SLOG_prof_t *profile ){    SLOG_intvlinfo_t       *info;    SLOG_intvlinfo_t        joined_info;    SLOG_uint32             idx_begin, idx_end;    SLOG_uint32             ii, jj;    int                     DoPartIntvlsExist4itype;    int                     Nerrors;#if defined( DEBUG )    if ( profile == NULL ) {        fprintf( errfile, __FILE__":SLOG_PROF_IsBebitIntvlsConsistent() - \n"                          "\t""the SLOG_prof_t pointer in slog "                          "is NULL\n" );        fflush( errfile );        return SLOG_FALSE;    }#endif    /*  Sort the table in increasing intvltype and bebits order  */    SLOG_PROF_SortTable( profile );    /*        The following statements assume intvltype will be changed when        bebits are recycled    */    DoPartIntvlsExist4itype = SLOG_FALSE;    idx_begin               = 0;    Nerrors                 = 0;    for ( ii = 0; ii < profile->Nentries; ii++ ) {        /*        fprintf( outfile, "%d >  ", ii );        SLOG_IntvlInfo_Print( &( profile->entries[ ii ] ), outfile );        fprintf( outfile, "\n" );        fflush( outfile );        */                info = &( profile->entries[ ii ] );        if ( ! SLOG_bebits_IsWholeIntvl( info->bebits ) ) {            if ( ! DoPartIntvlsExist4itype ) {                /*  The 1st bebit interval  */                idx_begin = ii;                SLOG_IntvlInfo_Assign( &joined_info,                                       info->intvltype, 1, 1,                                       info->classtype, info->label,                                       info->color );                joined_info.arg_labels = SLOG_StrList_Copy( info->arg_labels );            }            else {                /*  The non-1st bebit interval, but NOT whole interval  */                idx_end = ii;                if (    info->intvltype != joined_info.intvltype                      || strcmp( info->classtype, joined_info.classtype ) != 0                       || strcmp( info->label    , joined_info.label     ) != 0                       || strcmp( info->color    , joined_info.color     ) != 0 )                {                    fprintf( errfile, __FILE__                                      ":SLOG_PROF_IsBebitIntvlsConsistent() -\n"                                      "\t""Inconsistency detected for "                                      "intvltype = "fmt_itype_t"\n",                                      info->intvltype );                    for ( jj = idx_begin; jj <= idx_end; jj++ ) {                        fprintf( errfile, "%d, ", jj );                        SLOG_IntvlInfo_Print( &( profile->entries[ jj ] ),                                              errfile );                        fprintf( errfile, "\n" );                    }                    fflush( errfile );                    Nerrors ++;                    /* return SLOG_FALSE; */                }                joined_info.arg_labels                = SLOG_StrList_Append( joined_info.arg_labels,                                       info->arg_labels );            }            DoPartIntvlsExist4itype  = SLOG_TRUE;        }        else {  /*  if ( SLOG_bebits_IsWholeIntvl( info->bebits ) )  */            /*  The whole bebit interval  */            idx_end = ii;            if ( DoPartIntvlsExist4itype ) {                if ( ! SLOG_IntvlInfo_IsEqualTo( &joined_info, info ) ) {                    fprintf( errfile, __FILE__                                      ":SLOG_PROF_IsBebitIntvlsConsistent() -\n"                                      "\t""Inconsistency detected for "                                      "intvltype = "fmt_itype_t"\n",                                      info->intvltype );                    for ( jj = idx_begin; jj <= idx_end; jj++ ) {                        fprintf( errfile, "%d, ", jj );                        SLOG_IntvlInfo_Print( &( profile->entries[ jj ] ),                                              errfile );                        fprintf( errfile, "\n" );                    }                    fflush( errfile );                    Nerrors ++;                    /* return SLOG_FALSE; */                }                SLOG_StrList_Free( joined_info.arg_labels );                joined_info.arg_labels = NULL;            }            DoPartIntvlsExist4itype = SLOG_FALSE;        }        /*        fprintf( outfile, "j >  ");        SLOG_IntvlInfo_Print( &joined_info, outfile );        fprintf( outfile, "\n" );        fflush( outfile );        */            }    if ( Nerrors > 0 )        return SLOG_FALSE;    else        return SLOG_TRUE;}int SLOG_PROF_CompressTable( SLOG_prof_t *profile ){    SLOG_intvlinfo_t       *entries_used;    SLOG_intvlinfo_t       *info;    SLOG_intvltype_t        prev_used_itype;    SLOG_uint32             Nentries_used;    SLOG_uint32             idx, ii;    int                     itmp;#if defined( DEBUG )    if ( profile == NULL ) {        fprintf( errfile, __FILE__":SLOG_PROF_CompressTable() - "                          "the SLOG_prof_t pointer in slog "                          "is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }#endif    /*  Sort the display profile in increasing intvltype and bebits order  */    SLOG_PROF_SortTable( profile );    /*  Set idx to first non scanned but used entry  */    itmp = -1;    for ( idx = 0; idx < profile->Nentries && itmp != -1; idx++ ) {        info = &( profile->entries[ idx ] );        if ( info->used )            itmp = info->intvltype;    }    /*         If any of partial bebit intervals is set,        set the whole interval as used    */    for ( prev_used_itype = itmp; idx < profile->Nentries; idx++ ) {        info = &( profile->entries[ idx ] );        if ( info->used )            prev_used_itype = info->intvltype;        else {            if (    SLOG_bebits_IsWholeIntvl( info->bebits )                  && info->intvltype == prev_used_itype ) {                 SLOG_IntvlInfo_SetUsed( info, SLOG_TRUE );            }        }    }    /*  Compute the Number of __used__ entries in the display profile table  */    Nentries_used = 0;    for ( ii = 0; ii < profile->Nentries; ii++ )        if ( ( profile->entries[ ii ] ).used )            Nentries_used++;    if ( Nentries_used == profile->Nentries )        return SLOG_SUCCESS;    /*  Allocate the temporary storage for the used definition  */    entries_used = ( SLOG_intvlinfo_t * )                   malloc( Nentries_used * sizeof( SLOG_intvlinfo_t ) );    if ( Nentries_used > 0 && entries_used == NULL ) {        fprintf( errfile, __FILE__":SLOG_PROF_CompressTable() - \n"                          "\t""malloc() for temporary storage, "                          "entries_used, fails for Nentries_used = "                          fmt_ui32" ! \n", Nentries_used );        fflush( errfile );        return SLOG_FAIL;    }    /*  Copy the used display profile definitions to the temporary storage  */    idx = 0;    for ( ii = 0; ii < profile->Nentries; ii++ ) {        info = &( profile->entries[ ii ] );        if ( info->used ) {            SLOG_IntvlInfo_Assign( &( entries_used[ idx ] ),                                   info->intvltype,                                    info->bebits[0], info->bebits[1],                                   info->classtype, info->label, info->color );            /*  Pointer Copy  */            entries_used[ idx ].arg_labels = info->arg_labels;            idx++;        }        else {            /*                Since a pointer copy has been done, so SLOG_IntvlInfo's                arg_labels needs to be freed when SLOG_IntvlInfo is NOT                 used( to avoid inconsistent memory leak )            */            SLOG_StrList_Free( info->arg_labels );            info->arg_labels = NULL;        }    }    /*  Throw away the original display profile table  */    if ( profile->Nentries > 0 && profile->entries != NULL ) {        free( profile->entries );        profile->entries    = NULL;        profile->capacity   = 0;        profile->Nentries   = 0;    }    /*          Shrink the original table in memory to store the used definitions         by pointing the display profile table to the temporary storage.    */    profile->capacity   = Nentries_used;    profile->Nentries   = Nentries_used;    profile->entries    = entries_used;    return SLOG_SUCCESS;}int SLOG_PROF_CompressedTableToFile( SLOG_STREAM  *slog ){    SLOG_prof_t            *profile;    SLOG_fptr               file_loc_saved;    SLOG_uint32             ii;    int                     ierr;    profile = slog->prof;#if defined( DEBUG )    if ( profile == NULL ) {        fprintf( errfile, __FILE__":SLOG_PROF_CompressedTableToFile() - "                          "the SLOG_prof_t pointer in slog "                          "is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }#endif    /*  Save the current position in the logfile for later restoration  */    file_loc_saved = slog_ftell( slog->fd );    /*  Update the number of record definitions on the file/disk  */    ierr = slog_fseek( slog->fd, slog->hdr->fptr2profile, SEEK_SET );    if ( ierr != 0 ) {        fprintf( errfile, __FILE__":SLOG_PROF_CompressedTableToFile() - \n"                          "\t""slog_fseek( fptr2profile ) fails\n" );        fflush( errfile );        return SLOG_FAIL;    }    ierr = bswp_fwrite( &( profile->Nentries ),                        sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_PROF_CompressedTableToFile() - \n"                          "\t""Update the number of entries in the profile "                          "definition table on the file fails\n" );        fflush( errfile );        return SLOG_FAIL;    }    for ( ii = 0; ii < profile->Nentries; ii++ ) {        ierr = SLOG_IntvlInfo_WriteToFile( &( profile->entries[ ii ] ),                                           slog->fd );        if ( ierr != SLOG_TRUE ) {            fprintf( errfile,  __FILE__":SLOG_PROF_CompressedTableToFile() - \n"                               "\t""SLOG_IntvlInfo_WriteToFile() fails at "                               "%d-th addition of the record definition to "                               "table section of logfile\n", ii );            fflush( errfile );            return SLOG_FAIL;        }    }    /*  Probably unnecessary  */    /*  Update the file pointer to the reserved space of RecDefs in file */    profile->file_loc = slog_ftell( slog->fd );    /*  Restore the original file position in the logfile  */    ierr = slog_fseek( slog->fd, file_loc_saved, SEEK_SET );    return SLOG_SUCCESS;}void SLOG_PROF_Free( SLOG_prof_t *profile ){    int ii;    if ( profile != NULL ) {        if ( profile->Nentries > 0 && profile->entries != NULL ) {            for ( ii = 0; ii < (int)profile->Nentries; ii ++ )                SLOG_StrList_Free( profile->entries[ ii ].arg_labels );            free( profile->entries );            profile->entries = NULL;        }        free( profile );        profile = NULL;    }}int SLOG_PROF_ReadIntvlInfos( SLOG_STREAM  *slog ){    SLOG_prof_t            *profile;    int                     ii;

⌨️ 快捷键说明

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