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

📄 clog_cache.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 2 页
字号:
        exit( 1 );    }    CLOG_Preamble_read( cache->preamble, cache->local_fd );    if ( cache->preamble->commtable_fptr < CLOG_PREAMBLE_SIZE ) {        fprintf( stderr, __FILE__":CLOG_Cache_open4readwrite() - Warning!\n"                         "\t""Invalid commtable_fptr, "i64fmt", < "                         "CLOG_PREAMBLE_SIZE, %d.\n"                         "\t""This program can fix this incomplete logfile.\n",                         cache->preamble->commtable_fptr, CLOG_PREAMBLE_SIZE );        fflush( stderr );        return;    }    lseek( cache->local_fd, cache->preamble->commtable_fptr, SEEK_SET );    do_byte_swap = (    cache->preamble->is_big_endian                     != cache->is_runtime_bigendian );    ierr = CLOG_CommSet_read( cache->commset, cache->local_fd, do_byte_swap );    if ( ierr <= 0 ) {        fprintf( stderr, __FILE__":CLOG_Cache_open4readwrite() - Warning!\n"                         "\t""CLOG_CommSet_read() return an error code, %d.\n"                         "\t""This program can fix this incomplete logfile.\n",                         ierr );        fflush( stderr );    }}/* This is for clog2_print to print the content of clog2 file */void CLOG_Cache_close4read( CLOG_Cache_t *cache ){ /*  Empty function for now. */ }/* This is for clog2_join to write multiple MPI_COMM_WORLD joined clog2 file */void CLOG_Cache_close4write( CLOG_Cache_t *cache ){    CLOG_BOOL_T  do_byte_swap;    int          ierr;        cache->preamble->commtable_fptr    = (CLOG_int64_t) lseek( cache->local_fd, 0, SEEK_CUR );    /* Save CLOG_CommSet_t to BigEndian file */    do_byte_swap = ( cache->preamble->is_big_endian != CLOG_BOOL_TRUE );    ierr = CLOG_CommSet_write( cache->commset, cache->local_fd, do_byte_swap );    if ( ierr < 0 ) {        fprintf( stderr, __FILE__":CLOG_Cache_close4write() - \n"                         "\t""CLOG_CommSet_write() fails!\n" );        fflush( stderr );        return;    }    /* Save updated CLOG_Preamble_t to the BigEndian and Finalized file */    lseek( cache->local_fd, 0, SEEK_SET );    CLOG_Preamble_write( cache->preamble, CLOG_BOOL_TRUE, CLOG_BOOL_TRUE,                         cache->local_fd );    close( cache->local_fd );}/* This is for clog2_repair to fix up incomplete file.  */void CLOG_Cache_close4readwrite( CLOG_Cache_t *cache ){    CLOG_BOOL_T  do_byte_swap;    int          ierr;        cache->preamble->commtable_fptr    = (CLOG_int64_t) lseek( cache->local_fd, 0, SEEK_CUR );    /* Save CLOG_CommSet_t to the file of the Same Endianess */    do_byte_swap = (    cache->preamble->is_big_endian                     != cache->is_runtime_bigendian );    ierr = CLOG_CommSet_write( cache->commset, cache->local_fd, do_byte_swap );    if ( ierr < 0 ) {        fprintf( stderr, __FILE__":CLOG_Cache_close4readwrite() - \n"                         "\t""CLOG_CommSet_write() fails!\n" );        fflush( stderr );        return;    }    /* Save updated CLOG_Preamble_t to the Same Endianness & Finalized file */    lseek( cache->local_fd, 0, SEEK_SET );    CLOG_Preamble_write( cache->preamble, CLOG_BOOL_NULL, CLOG_BOOL_NULL,                         cache->local_fd );    close( cache->local_fd );}/*    Iterator interface for CLOG_Cache_t (similar to Java's Iterator interface),    i.e. CLOG_Cache_has_rec() has to be called before each CLOG_Cache_get_rec()*/CLOG_BOOL_T CLOG_Cache_has_rec( CLOG_Cache_t *cache ){    CLOG_Rec_Header_t  *hdr;    hdr = (CLOG_Rec_Header_t *) cache->blockdata->ptr;    if ( hdr->rectype > CLOG_REC_ENDBLOCK && hdr->rectype < CLOG_REC_NUM )        return CLOG_BOOL_TRUE;    else {        if ( hdr->rectype == CLOG_REC_ENDBLOCK ) {            CLOG_Cache_fillblock( cache );            return CLOG_Cache_has_rec( cache );        }        if ( hdr->rectype == CLOG_REC_ENDLOG ) {            return CLOG_BOOL_FALSE;        }        fprintf( stderr, __FILE__":CLOG_Cache_has_next() - \n"                         "\t""Unknown record type "i32fmt".\n", hdr->rectype );        fflush( stderr );        exit( 1 );    }}/* Don't advance CLOG_BlockData_t's ptr unless get_rec() is called. */CLOG_Rec_Header_t* CLOG_Cache_get_rec( CLOG_Cache_t *cache ){    CLOG_Rec_Header_t  *hdr;    hdr = (CLOG_Rec_Header_t *) cache->blockdata->ptr;    /* Advance CLOG_Cache_t's BlockData pointer by 1 whole record length */    cache->blockdata->ptr += CLOG_Rec_size( hdr->rectype );    return hdr;}CLOG_Time_t CLOG_Cache_get_time( const CLOG_Cache_t *cache ){    CLOG_Rec_Header_t  *hdr;    hdr = (CLOG_Rec_Header_t *) cache->blockdata->ptr;    return hdr->time;}static int CLOG_Cache_reserved_block_size( CLOG_int32_t rectype ){    /* Have CLOG_Rec_size() do the error checking */    return CLOG_Rec_size( rectype ) + clog_cache_minblocksize;}/* CLOG_Cache_put_rec() write to the cache which will be writing to disk */void CLOG_Cache_put_rec( CLOG_Cache_t *cache, const CLOG_Rec_Header_t *hdr ){    CLOG_BlockData_t   *blkdata;    CLOG_Rec_Header_t  *last_hdr;    int                 reclen;    blkdata = cache->blockdata;    /* Write a CLOG_REC_ENDBLOCK record */    if (    blkdata->ptr + CLOG_Cache_reserved_block_size( hdr->rectype )         >= blkdata->tail ) {        last_hdr = (CLOG_Rec_Header_t *) blkdata->ptr;        last_hdr->time    = hdr->time;        last_hdr->icomm   = hdr->icomm;         /* arbitary */         last_hdr->rank    = hdr->rank;          /* arbitary */        last_hdr->thread  = hdr->thread;        /* arbitary */        last_hdr->rectype = CLOG_REC_ENDBLOCK;        CLOG_Cache_flushblock( cache );    }    /* Save the CLOG record into the CLOG_BlockData_t */    reclen = CLOG_Rec_size( hdr->rectype );    memcpy( blkdata->ptr, hdr, reclen );    blkdata->ptr += reclen;}CLOG_CacheLink_t* CLOG_CacheLink_create( CLOG_Cache_t* cache ){    CLOG_CacheLink_t  *cachelink;    cachelink = (CLOG_CacheLink_t *) MALLOC( sizeof(CLOG_CacheLink_t) );    if ( cachelink == NULL ) {        fprintf( stderr, __FILE__":CLOG_CacheLink_create() - "                         "MALLOC() fails for CLOG_CacheLink_t!\n" );        fflush( stderr );        return NULL;    }    cachelink->cache  = cache;    cachelink->prev   = NULL;    cachelink->next   = NULL;    return cachelink;}void CLOG_CacheLink_free( CLOG_CacheLink_t **cachelink_handle ){    CLOG_CacheLink_t  *cachelink;    cachelink  = *cachelink_handle;    if ( cachelink != NULL ) {        FREE( cachelink );    }    *cachelink_handle = NULL;}/*   Detach "detach" from the List pointed by "*head_handle" & "*tail_handle"   "detach" is assumed to be non-NULL.*/void CLOG_CacheLink_detach( CLOG_CacheLink_t **head_handle,                            CLOG_CacheLink_t **tail_handle,                            CLOG_CacheLink_t  *detach ){    if ( detach->prev != NULL ) {        detach->prev->next = detach->next;        /*        detach->prev       = NULL;        Cannot set detach->prev to NULL yet as it may be needed later.        */    }    else { /* (detach->prev == NULL) <=> (detach == *head_handle) */        if ( detach->next != NULL ) {            (*head_handle)        = detach->next;            (*head_handle)->prev  = NULL;        }        else            (*head_handle)        = NULL;    }    if ( detach->next != NULL ) {        detach->next->prev = detach->prev;        /*        detach->next       = NULL;        Don't set detach->next to NULL here to be in parallel to the code above.        */    }    else { /* (detach->next == NULL) <=> (detach == *tail_handle) */        if ( detach->prev != NULL ) {            (*tail_handle)        = detach->prev;            (*tail_handle)->next  = NULL;        }        else            (*tail_handle)        = NULL;    }    /* Make sure that the detach is really detached to any links */    detach->prev  = NULL;    detach->next  = NULL;}/* Append "curr" after "*tail_handle", then Advance "*tail_handle" */void CLOG_CacheLink_append( CLOG_CacheLink_t **head_handle,                            CLOG_CacheLink_t **tail_handle,                            CLOG_CacheLink_t  *curr ){    /* CLOG_CacheLink_t *tail; tail = *tail_handle */    curr->prev            = *tail_handle;    curr->next            = NULL;    if ( *tail_handle != NULL ) /* *head_handle != *tail_handle != NULL */        (*tail_handle)->next  = curr;    else  /* *head_handle == *tail_handle == NULL */        (*head_handle)    = curr;    (*tail_handle)        = curr;}/*    location is    1) either between *head_handle and *tail_handle       *head_handle <= location <= *tail_handle    2) or NULL, i.e. after *tail_handle       *head_handle <= *tail_handle < location(=NULL)    Therefore    insert <= location , i.e. insert comes before location.    CLOG_CacheLink_insert( &head, &tail, NULL, insert ) is functionally    the same as CLOG_Cache_append( &head, &tail, insert );*/void CLOG_CacheLink_insert( CLOG_CacheLink_t **head_handle,                            CLOG_CacheLink_t **tail_handle,                            CLOG_CacheLink_t  *location,                            CLOG_CacheLink_t  *insert ){     /*  before <= insert <= after */     CLOG_CacheLink_t  *before, *after;     /* connect the "insert" with "after" */     after  = location;     if ( after != NULL ) {         before        = after->prev;         after->prev   = insert;     }     else {         before        = *tail_handle;         *tail_handle  = insert;     }     insert->next  = after;     /* connect the "insert" with "before" */     if ( before != NULL )         before->next  = insert;     else         *head_handle  = insert;     insert->prev  = before;}

⌨️ 快捷键说明

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