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

📄 slog_recdefs.c

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 C
📖 第 1 页 / 共 3 页
字号:
        fprintf( errfile, __FILE__":SLOG_RDEF_CompressedTableToFile() - "                          "the SLOG_recdefs_table_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->fptr2recdefs, SEEK_SET );    if ( ierr != 0 ) {        fprintf( errfile, __FILE__":SLOG_RDEF_CompressedTableToFile() - \n"                          "\t""slog_fseek( fptr2recdefs ) fails\n" );        fflush( errfile );        return SLOG_FAIL;    }    ierr = bswp_fwrite( &( recdefs->Nentries ),                        sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_RDEF_CompressedTableToFile() - \n"                          "\t""Update the number of entries in the record "                          "definition table on the file fails\n" );        fflush( errfile );        return SLOG_FAIL;    }    for ( ii = 0; ii < recdefs->Nentries; ii++ ) {        ierr = SLOG_RecDef_WriteToFile( &( recdefs->entries[ ii ] ),                                        slog->fd );        if ( ierr != SLOG_TRUE ) {            fprintf( errfile,  __FILE__":SLOG_RDEF_CompressedTableToFile() - \n"                               "\t""SLOG_RecDef_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 */    recdefs->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_RDEF_Free( SLOG_recdefs_table_t *recdefs ){    if ( recdefs != NULL ) {        if ( recdefs->Nentries > 0 && recdefs->entries != NULL ) {            free( recdefs->entries );            recdefs->entries = NULL;        }        free( recdefs );        recdefs = NULL;    }}int SLOG_RDEF_ReadRecDefs( SLOG_STREAM  *slog ){    SLOG_recdefs_table_t   *recdefs;    int                     ii;    int                     ierr;    slog->rec_defs = ( SLOG_recdefs_table_t * )                     malloc( sizeof( SLOG_recdefs_table_t ) );    if ( slog->rec_defs == NULL ) {        fprintf( errfile, __FILE__":SLOG_RDEF_ReadRecDefs() - "                          "malloc() fails, Cannot allocate memory for "                          "SLOG_recdefs_table_t\n" );        fflush( errfile );        return SLOG_FAIL;    }    /*  Initialize the Record Definition table data structure  */    slog->rec_defs->increment  = 10;    slog->rec_defs->capacity   = slog->rec_defs->increment;    slog->rec_defs->Nentries   = 0;    slog->rec_defs->entries    = NULL;        /*  Seek to the beginning of the Record Def'n Table in the SLOG file  */    if ( slog->hdr->fptr2recdefs == SLOG_fptr_NULL ) {        fprintf( errfile, __FILE__":SLOG_RDEF_ReadRecDefs() - "                          "slog->hdr->fptr2recdefs == SLOG_fptr_NULL\n" );        fprintf( errfile, "\t""SLOG_RDEF_Close() may NOT be called\n" );        fflush( errfile );        return SLOG_FAIL;    }    ierr = slog_fseek( slog->fd, slog->hdr->fptr2recdefs, SEEK_SET );    if ( ierr != 0 ) {        fprintf( errfile, __FILE__":SLOG_RDEF_ReadRecDefs() - "                          "slog_fseek( fptr2recdefs ) fails\n" );        fflush( errfile );        return SLOG_FAIL;    }    /*  Read in the data structure  */    recdefs = slog->rec_defs;        ierr = bswp_fread( &( recdefs->Nentries ),                       sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile, __FILE__":SLOG_RDEF_ReadRecDefs() - \n"                          "\t""Fails at reading the number of entries "                          "of the record definition table\n" );        fflush( errfile );        return SLOG_FAIL;    }    recdefs->capacity = recdefs->Nentries;    recdefs->entries  = ( SLOG_recdef_t * )                        malloc( recdefs->capacity * sizeof( SLOG_recdef_t ) );    if ( recdefs->Nentries > 0 && recdefs->entries == NULL ) {        fprintf( errfile, __FILE__":SLOG_RDEF_ReadRecDefs() - "                          "malloc() fails for recdefs->entries[]\n" );        fflush( errfile );        return SLOG_FAIL;    }        for ( ii = 0; ii < (int)recdefs->Nentries; ii++ ) {        ierr = SLOG_RecDef_ReadFromFile( &( recdefs->entries[ ii ] ),                                          slog->fd );        if ( ierr != SLOG_TRUE ) {            fprintf( errfile, __FILE__":SLOG_RDEF_ReadRecDefs() - \n"                              "\t""SLOG_RecDef_ReadFromFile() fails at "                              "%d-th reading of record definition from "                              "the table section of logfile\n", ii );            fflush( errfile );             return SLOG_FAIL;        }    }      return SLOG_SUCCESS;}void SLOG_RDEF_Print( FILE* fd, const SLOG_recdefs_table_t *recdefs ){    int ii;    for ( ii = 0; ii < (int)recdefs->Nentries; ii++ ) {        fprintf( fd, " def[%i] = ", ii );        SLOG_RecDef_Print( &( recdefs->entries[ ii ] ), fd );        fprintf( fd, "\n" );    }    fflush( fd );}/*  -- Component level supporting subroutines  -- */        /* SLOG_RecDef_xxxx methods */void SLOG_RecDef_Assign(       SLOG_recdef_t        *recdef,                         const SLOG_intvltype_t      in_intvltype,                         const SLOG_bebit_t          in_bebit_0,                         const SLOG_bebit_t          in_bebit_1,                         const SLOG_N_assocs_t       in_Nassocs,                         const SLOG_N_args_t         in_Nargs ){    recdef->intvltype = in_intvltype;    recdef->bebits[0] = in_bebit_0;    recdef->bebits[1] = in_bebit_1;    recdef->Nassocs   = in_Nassocs;    recdef->Nargs     = in_Nargs;}void SLOG_RecDef_Print( const SLOG_recdef_t *def, FILE *fd ){    fprintf( fd, "[ "fmt_itype_t", ("fmt_bebit_t", "fmt_bebit_t"), "                 fmt_Nassocs_t", "fmt_Nargs_t" ]",                  def->intvltype, def->bebits[0], def->bebits[1],                 def->Nassocs, def->Nargs );}int SLOG_RecDef_WriteToFile( const SLOG_recdef_t *def, FILE *fd ){    SLOG_bebits_t           bebits;    int                     ierr;    ierr = bswp_fwrite( &( def->intvltype ),                        sizeof( SLOG_intvltype_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    bebits = SLOG_bebits_encode( def->bebits[0], def->bebits[1] );    ierr = bswp_fwrite( &( bebits ),                        sizeof( SLOG_bebits_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    ierr = bswp_fwrite( &( def->Nassocs ),                        sizeof( SLOG_N_assocs_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    ierr = bswp_fwrite( &( def->Nargs ),                        sizeof( SLOG_N_args_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    return SLOG_TRUE;}int SLOG_RecDef_ReadFromFile( SLOG_recdef_t *def, FILE *fd ){    SLOG_bebits_t           bebits;    int                     ierr;    ierr = bswp_fread( &( def->intvltype ),                       sizeof( SLOG_intvltype_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    ierr = bswp_fread( &( bebits ),                       sizeof( SLOG_bebits_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    SLOG_bebits_decode( bebits, def->bebits );    ierr = bswp_fread( &( def->Nassocs ),                       sizeof( SLOG_N_assocs_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    ierr = bswp_fread( &( def->Nargs ),                       sizeof( SLOG_N_args_t ), 1, fd );    if ( ierr < 1 ) return SLOG_FALSE;    return SLOG_TRUE;}int SLOG_RecDef_IsKeyEqualTo( const SLOG_recdef_t *def1,                              const SLOG_recdef_t *def2 ){    return (    ( def1->intvltype == def2->intvltype )             && ( def1->bebits[0] == def2->bebits[0] )             && ( def1->bebits[1] == def2->bebits[1] ) );}int SLOG_RecDef_IsValueEqualTo( const SLOG_recdef_t *def1,                                const SLOG_recdef_t *def2 ){    return (    ( def1->Nassocs == def2->Nassocs )             && ( def1->Nargs   == def2->Nargs ) );}int SLOG_RecDef_IsEqualTo( const SLOG_recdef_t *def1,                           const SLOG_recdef_t *def2 ){    return (    SLOG_RecDef_IsKeyEqualTo( def1, def2 )             && SLOG_RecDef_IsValueEqualTo( def1, def2 ) );}/*  Looks up the total number of associations for given record type  *//*  SLOG_N_assocs_t  */SLOG_int32SLOG_RecDef_NumOfAssocs( const SLOG_recdefs_table_t   *recdefs,                         const SLOG_intvltype_t        intvltype,                         const SLOG_bebit_t            bebit_0,                         const SLOG_bebit_t            bebit_1 ){    SLOG_recdef_t  *cur_def;    int             ii;    for ( ii = 0; ii < (int)recdefs->Nentries; ii++ ) {        cur_def = &( recdefs->entries[ ii ] );        if (    ( cur_def->intvltype == intvltype )             && ( cur_def->bebits[0] == bebit_0 )             && ( cur_def->bebits[1] == bebit_1 ) )            return cur_def->Nassocs;    }    fprintf( errfile, __FILE__":SLOG_RecDef_NumOfAssocs() - "                      "Cannot find [ intvltype = "fmt_itype_t", ("                      fmt_bebit_t", "fmt_bebit_t") ] "                      "in the Record Definition Table\n",                      intvltype, bebit_0, bebit_1 );    fflush( errfile );    return SLOG_FAIL;}/*  Looks up the number of all the MPI arguments for given record type  *//*  SLOG_N_args_t  */SLOG_int32SLOG_RecDef_NumOfArgs( const SLOG_recdefs_table_t   *recdefs,                       const SLOG_intvltype_t        intvltype,                       const SLOG_bebit_t            bebit_0,                       const SLOG_bebit_t            bebit_1 ){    SLOG_recdef_t  *cur_def;    int             ii;    for ( ii = 0; ii < (int)recdefs->Nentries; ii++ ) {        cur_def = &( recdefs->entries[ ii ] );        if (    ( cur_def->intvltype == intvltype )             && ( cur_def->bebits[0] == bebit_0 )             && ( cur_def->bebits[1] == bebit_1 ) )            return cur_def->Nargs;    }    fprintf( errfile, __FILE__":SLOG_RecDef_NumOfArgs() - "                      "Cannot find [ intvltype = "fmt_itype_t", ("                      fmt_bebit_t", "fmt_bebit_t") ] "                      "in the Record Definition Table\n",                      intvltype, bebit_0, bebit_1 );    fflush( errfile );    return SLOG_FAIL;}/*   This routine can be modified to give the maximum possible size for   the corresponding interval record, even for __variable__ interval record.   if the N_args column in Record Definition Table is modified to give   the maximum estimated size of the set of vector arguments.*/SLOG_int32SLOG_RecDef_SizeOfIrecInFile( const SLOG_recdefs_table_t   *recdefs,                              const SLOG_rectype_t          rectype,                               const SLOG_intvltype_t        intvltype,                              const SLOG_bebit_t            bebit_0,                              const SLOG_bebit_t            bebit_1 ){    int              sizeof_irec;        SLOG_N_assocs_t  N_assocs;    SLOG_N_args_t    N_args;    if ( SLOG_global_IsVarRec( rectype ) ) {        fprintf( errfile, __FILE__":SLOG_RecDef_SizeOfIrecInFile() - \n" );        fprintf( errfile, "\t""the input rectype, "fmt_rtype_t", is variable "                          "interval record\n", rectype );        fflush( errfile );        return SLOG_FAIL;    }    N_assocs = SLOG_RecDef_NumOfAssocs( recdefs, intvltype, bebit_0, bebit_1 );    N_args   = SLOG_RecDef_NumOfArgs( recdefs, intvltype, bebit_0, bebit_1 );    sizeof_irec = SLOG_typesz[ min_IntvlRec ]                + N_assocs * sizeof( SLOG_assoc_t )                + N_args * sizeof( SLOG_arg_t );    if ( SLOG_global_IsOffDiagRec( rectype ) )        sizeof_irec += SLOG_typesz[ taskID_t ];    return sizeof_irec;}/*  boolean_flag can be either SLOG_TRUE or SLOG_FALSE  */void SLOG_RecDef_SetUsed(       SLOG_recdef_t *def,                          const int            boolean_flag ){    if ( def != NULL )        def->used = boolean_flag;}

⌨️ 快捷键说明

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