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

📄 slog_recdefs.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 "bswp_fileio.h"#include "slog_fileio.h"#include "slog_header.h"#include "slog_bebits.h"#include "slog_impl.h"#include "slog_recdefs.h"              /*I "slog_recdefs.h" I*/int SLOG_RDEF_IsDuplicated( const SLOG_recdefs_table_t  *recdefs,                            const SLOG_recdef_t         *in_def ){    SLOG_recdef_t  *cur_def;    int             ii;    int             NotMatched = 1;    for ( ii = 0; NotMatched && (ii < (int)recdefs->Nentries); ii++ ) {        cur_def = &( recdefs->entries[ ii ] );        NotMatched = ! SLOG_RecDef_IsKeyEqualTo( cur_def, in_def );    }    return ! NotMatched;}/*@C    SLOG_RDEF_Open - Creates the SLOG Record Definition Table,                      SLOG_recdefs_table_t, needed to write the to                     the disk.  Modified Input Variables :. slog - pointer to the SLOG_STREAM where SLOG Record Definition Table is         located.  Modified Output Variables :. returned value - integer return status.  Include file needed :   slog_recdefs.h.N SLOG_RETURN_STATUS@*/int SLOG_RDEF_Open( SLOG_STREAM  *slog ){    slog->rec_defs = ( SLOG_recdefs_table_t * )                     malloc( sizeof( SLOG_recdefs_table_t ) );    if ( slog->rec_defs == NULL ) {        fprintf( errfile, __FILE__":SLOG_RDEF_Open() - "                          "malloc() fails, Cannot allocate memory for "                          "SLOG_recdefs_table_t\n" );        fflush( errfile );        return SLOG_FAIL;    }    slog->rec_defs->increment  = 10;    slog->rec_defs->capacity   = slog->rec_defs->increment;    slog->rec_defs->Nentries   = 0;    slog->rec_defs->entries    = ( SLOG_recdef_t * )                                 malloc(   slog->rec_defs->capacity                                         * sizeof( SLOG_recdef_t ) );    slog->rec_defs->file_loc   = SLOG_fptr_NULL;    return SLOG_SUCCESS;}/*@C    SLOG_RDEF_AddRecDef - Add one definition to the SLOG Record Definition                          table.  Modified Input Variables :. slog - pointer to the SLOG_STREAM where SLOG Record Definition Table is         located.  Unmodified Input Variables :. intvltype - label to the interval type.. bebit_0 - the 1st bebit.. bebit_1 - the 2nd bebit.. Nassocs - Number of assocications for this interval record type.. Nargs - Number of MPI call argument for this interval record type.  Modified Output Variables :. returned value - integer return status.  Usage Notes on this subroutine :.N SLOG_EXTRA_RECDEFS  Include file needed :   slog_recdefs.h.N SLOG_RETURN_STATUS@*/int SLOG_RDEF_AddRecDef(       SLOG_STREAM          *slog,                         const SLOG_intvltype_t      intvltype,                         const SLOG_bebit_t          bebit_0,                         const SLOG_bebit_t          bebit_1,                         const SLOG_N_assocs_t       Nassocs,                         const SLOG_N_args_t         Nargs ){    SLOG_uint32             idx;    SLOG_recdefs_table_t   *recdefs;    recdefs = slog->rec_defs;#if defined( DEBUG )    if ( recdefs == NULL ) {        fprintf( errfile, __FILE__":SLOG_RDEF_AddRecDef() - "                          "the SLOG_recdefs_table_t pointer in slog "                          "is NULL\n" );        fflush( errfile );        return SLOG_FAIL;    }#endif    /*  Check if there is any space left for a new record definition */    if ( recdefs->Nentries + 1 > recdefs->capacity ) {        recdefs->capacity += recdefs->increment;        recdefs->entries = ( SLOG_recdef_t * )                           realloc( recdefs->entries,                                    recdefs->capacity * sizeof( SLOG_recdef_t )                                  );        if ( recdefs->entries == NULL ) {            fprintf( errfile, __FILE__":SLOG_RDEF_AddRecDef() - "                              "realloc() fails, cannot increase the size "                              "of recdefs->entries[]\n" );            fprintf( errfile, "\t""The input record definition = [ "fmt_itype_t                              ", ("fmt_bebit_t", "fmt_bebit_t                              "), "fmt_Nassocs_t", "fmt_Nargs_t" ] \n",                              intvltype, bebit_0, bebit_1, Nassocs, Nargs );            fflush( errfile );            return SLOG_FAIL;        }    }        idx = recdefs->Nentries;    SLOG_RecDef_Assign( &( recdefs->entries[ idx ] ),                        intvltype, bebit_0, bebit_1, Nassocs, Nargs );    SLOG_RecDef_SetUsed( &( recdefs->entries[ idx ] ), SLOG_FALSE );    if ( SLOG_RDEF_IsDuplicated( recdefs, &(recdefs->entries[ idx ]) ) ) {        fprintf( errfile, __FILE__":SLOG_RDEF_AddRecDef() - "                          "there is a copy of input record\n " );        fprintf( errfile, "\t""definition with identical keys "                          "in the SLOG record definition table\n" );        fprintf( errfile, "\t""The input record definition = [ "fmt_itype_t                          ", ("fmt_bebit_t", "fmt_bebit_t                          "), "fmt_Nassocs_t", "fmt_Nargs_t" ] \n",                          intvltype, bebit_0, bebit_1, Nassocs, Nargs );        fflush( errfile );        return SLOG_FAIL;    }    recdefs->Nentries += 1;    return SLOG_SUCCESS;}/*@C    SLOG_RDEF_Close - Write the SLOG_recdefs_table_t onto the disk  Modified Input Variables :. slog - pointer to the SLOG_STREAM where SLOG Record Definition Table is         located.  Modified Output Variables :. returned value - integer status code.  Usage Notes on this subroutine :.N SLOG_EXTRA_RECDEFS  Include file needed :   slog_recdefs.h.N SLOG_RETURN_STATUS@*/int SLOG_RDEF_Close( SLOG_STREAM  *slog ){    SLOG_recdefs_table_t   *recdefs;    int                     ierr;    int                     ii;    /*  Update the content of SLOG_hdr_t to both memory and disk  */    slog->hdr->fptr2recdefs = slog_ftell( slog->fd );    ierr = SLOG_WriteUpdatedHeader( slog );    if ( ierr != SLOG_SUCCESS ) {        fprintf( errfile,  __FILE__":SLOG_RDEF_Close() - "                                   "SLOG_WriteUpdatedHeader() fails\n" );        fflush( errfile );        return ierr;    }    /*  Write the content of SLOG Record Definition Table to the disk  */    recdefs = slog->rec_defs;        ierr = bswp_fwrite( &( recdefs->Nentries ),                        sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile,  __FILE__":SLOG_RDEF_Close() - \n"                           "\t""fails at "                           "writing the number of record definitions to "                           "table section of logfile\n" );        fflush( errfile );        return SLOG_FAIL;    }    for ( ii = 0; ii < (int)recdefs->Nentries; ii++ ) {        ierr = SLOG_RecDef_WriteToFile( &( recdefs->entries[ ii ] ),                                        slog->fd );        if ( ierr != SLOG_TRUE ) {            fprintf( errfile,  __FILE__":SLOG_RDEF_Close() - \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;        }    }      return SLOG_SUCCESS;}/*@C    SLOG_RDEF_SetExtraNumOfRecDefs - Write the starting file pointer                                      SLOG_recdefs_table_t to the slog's                                     header and then set the maximum                                      extra number of Record Definitions.  Modified Input Variables :. slog - pointer to the SLOG_STREAM where SLOG Record Definition Table is         located.  Unmodifued Input Variables :. Nentries_extra - Number of extra record definitions to be reserved                   on the disk  Modified Output Variables :. returned value - integer status code.  Usage Notes on this subroutine :.N SLOG_EXTRA_RECDEFS  Include file needed :   slog_recdefs.h.N SLOG_RETURN_STATUS@*/int SLOG_RDEF_SetExtraNumOfRecDefs(       SLOG_STREAM  *slog,                                    const SLOG_uint32   Nentries_extra ){    SLOG_recdefs_table_t   *recdefs;    SLOG_recdef_t           blank_def = { 0, {0,0}, 0, 0, 0 };    SLOG_uint32             old_recdefs_capacity;    int                     ierr;    int                     ii;    /*  Update the content of SLOG_hdr_t to both memory and disk  */    slog->hdr->fptr2recdefs = slog_ftell( slog->fd );    ierr = SLOG_WriteUpdatedHeader( slog );    if ( ierr != SLOG_SUCCESS ) {        fprintf( errfile,  __FILE__":SLOG_RDEF_SetExtraNumOfRecDefs() - "                                   "SLOG_WriteUpdatedHeader() fails\n" );        fflush( errfile );        return ierr;    }    recdefs = slog->rec_defs;        /*  Determine the new storage  */    old_recdefs_capacity = recdefs->capacity;    recdefs->capacity    = recdefs->Nentries + Nentries_extra;    recdefs->entries = ( SLOG_recdef_t * )                       realloc( recdefs->entries,                                recdefs->capacity * sizeof( SLOG_recdef_t )                              );    if ( recdefs->entries == NULL ) {        fprintf( errfile, __FILE__":SLOG_RDEF_SetExtraNumOfRecDefs() - "                          "realloc() fails, cannot increase the size "                          "of recdefs->entries["fmt_ui32"]\n",                          recdefs->capacity );        fflush( errfile );        recdefs->capacity = old_recdefs_capacity;        return SLOG_FAIL;    }    /*  Write the content of SLOG Record Definition Table to the disk  */    ierr = bswp_fwrite( &( recdefs->Nentries ),                        sizeof( SLOG_uint32 ), 1, slog->fd );    if ( ierr < 1 ) {        fprintf( errfile,  __FILE__":SLOG_RDEF_SetExtraNumOfRecDefs() - \n"                           "\t""fails at "                           "writing the number of record definitions to "                           "table section of logfile\n" );        fflush( errfile );        return SLOG_FAIL;    }    for ( ii = 0; ii < (int)recdefs->Nentries; ii++ ) {        ierr = SLOG_RecDef_WriteToFile( &( recdefs->entries[ ii ] ),                                         slog->fd );        if ( ierr != SLOG_TRUE ) {            fprintf( errfile,  __FILE__":SLOG_RDEF_SetExtraNumOfRecDefs() - \n"                               "\t""SLOG_RecDef_WriteToFile() fails at the "                               "%d-th addition of the record definition to "                               "table section of logfile\n", ii );            fflush( errfile );             return SLOG_FAIL;        }    }    /*  Save the location where the extra record definition can be inserted  */    recdefs->file_loc = slog_ftell( slog->fd );     /*  Write some blank record definitions to fill up the reserved space.  */    for ( ii = recdefs->Nentries; ii < (int)recdefs->capacity; ii++ ) {        ierr = SLOG_RecDef_WriteToFile( &blank_def, slog->fd );        if ( ierr != SLOG_TRUE ) {            fprintf( errfile,  __FILE__":SLOG_RDEF_SetExtraNumOfRecDefs() - \n"                               "\t""SLOG_RecDef_WriteToFile() fails at "                               "%d-th addition of the blank definition to "                               "table section of logfile\n", ii );            fflush( errfile );             return SLOG_FAIL;        }    }      return SLOG_SUCCESS;}/*@C    SLOG_RDEF_AddExtraRecDef - Add one extra definition to the reserved                               space of SLOG Record Definition table.  Modified Input Variables :. slog - pointer to the SLOG_STREAM where SLOG Record Definition Table is         located.  Unmodified Input Variables :. intvltype - label to the interval type.. bebit_0 - the 1st bebit.. bebit_1 - the 2nd bebit.. Nassocs - Number of assocications for this interval record type.. Nargs - Number of MPI call argument for this interval record type.  Modified Output Variables :. returned value - integer return status.  Usage Notes on this subroutine :.N SLOG_EXTRA_RECDEFS  Include file needed :   slog_recdefs.h

⌨️ 快捷键说明

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