root/ompi/mca/sharedfp/individual/sharedfp_individual_insert_metadata.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_sharedfp_individual_insert_metadata
  2. mca_sharedfp_individual_write_metadata_file

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2005 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2013-2016 University of Houston. All rights reserved.
  13  * $COPYRIGHT$
  14  *
  15  * Additional copyrights may follow
  16  *
  17  * $HEADER$
  18  */
  19 
  20 
  21 #include "ompi_config.h"
  22 #include "sharedfp_individual.h"
  23 
  24 #include "mpi.h"
  25 #include "ompi/constants.h"
  26 #include "ompi/mca/sharedfp/sharedfp.h"
  27 #include "ompi/mca/sharedfp/base/base.h"
  28 
  29 #include <stdlib.h>
  30 #include <stdio.h>
  31 #include "mpi.h"
  32 
  33 int mca_sharedfp_individual_insert_metadata(int functype,long recordlength,struct mca_sharedfp_base_data_t *sh )
  34 {
  35     int ret = OMPI_SUCCESS;
  36     mca_sharedfp_individual_metadata_node *newnode = NULL;
  37     mca_sharedfp_individual_metadata_node *tempnode = NULL;
  38     mca_sharedfp_individual_header_record *headnode = NULL;
  39 
  40     headnode = (mca_sharedfp_individual_header_record*)sh->selected_module_data;
  41     if ( NULL == headnode)  {
  42         opal_output (0, "sharedfp_individual_insert_metadat: headnode is NULL but file is open\n");
  43         return OMPI_ERROR;
  44     }
  45 
  46 
  47     if ( mca_sharedfp_individual_verbose ) {
  48         opal_output(ompi_sharedfp_base_framework.framework_output,
  49                     "sharedfp_individual_insert_metadata: Headnode->numofrecords = %d\n",
  50                     headnode->numofrecords);
  51     }
  52     /* Check if the maximum limit is reached for the records in the linked list*/
  53     if (headnode->numofrecords == MAX_METADATA_RECORDS) {
  54         /* Entire linked list is now deleted and a new file*/
  55         ret = mca_sharedfp_individual_write_metadata_file(sh);
  56         headnode->next = NULL;
  57     }
  58 
  59     /* Allocate a new Node */
  60     newnode = (mca_sharedfp_individual_metadata_node*)malloc(sizeof(mca_sharedfp_individual_metadata_node));
  61     if (NULL == newnode) {
  62         opal_output(0,"mca_sharedfp_individual_insert_metadata:Error while allocating new node\n");
  63         return OMPI_ERR_OUT_OF_RESOURCE;
  64     }
  65 
  66 
  67     /*numofrecords will always carry the number of records present in the metadata linked list*/
  68     headnode->numofrecords      = headnode->numofrecords + 1;
  69 
  70     newnode->recordid           = functype;
  71     newnode->timestamp          = mca_sharedfp_individual_gettime();
  72     newnode->localposition      = headnode->datafile_offset;            /* Datafile offset*/
  73     newnode->recordlength       = recordlength;
  74     newnode->next               = NULL;
  75 
  76 
  77     if ( headnode->next == NULL) {
  78         /*headnode allocated but no further metadata node is allocated*/
  79         headnode->next = newnode;
  80     }
  81     else {
  82         /*We need to append the new node*/
  83         tempnode = headnode->next;
  84 
  85         while(tempnode->next) {
  86             tempnode = tempnode->next;
  87         }
  88 
  89         tempnode->next = newnode;
  90     }
  91 
  92     return ret;
  93 }
  94 
  95 int mca_sharedfp_individual_write_metadata_file(struct mca_sharedfp_base_data_t *sh)
  96 {
  97     mca_sharedfp_individual_metadata_node *current = NULL;
  98     struct mca_sharedfp_individual_record2 buff;
  99     mca_sharedfp_individual_header_record *headnode = NULL;
 100     int ret=OMPI_SUCCESS;
 101     MPI_Status status;
 102 
 103     headnode = (mca_sharedfp_individual_header_record*)sh->selected_module_data;
 104 
 105     if (headnode->numofrecordsonfile == 0)
 106         headnode->metadatafile_offset = headnode->metafile_start_offset;
 107 
 108     current = headnode->next;
 109     while (current != NULL)  {
 110         /*Read from the linked list*/
 111 
 112         buff.recordid = current->recordid;
 113         buff.timestamp = current->timestamp;
 114         buff.localposition = current->localposition;
 115         buff.recordlength = current->recordlength;
 116 
 117         if ( mca_sharedfp_individual_verbose ) {
 118             opal_output(ompi_sharedfp_base_framework.framework_output,
 119                         "sharedfp_individual_write_metadata_file: Buff recordid %ld\n",buff.recordid);
 120             opal_output(ompi_sharedfp_base_framework.framework_output,
 121                         "sharedfp_individual_write_metadata_file: Buff timestamp %f\n", buff.timestamp);
 122             opal_output(ompi_sharedfp_base_framework.framework_output,
 123                         "sharedfp_individual_write_metadata_file: Buff localposition %lld\n",buff.localposition);
 124             opal_output(ompi_sharedfp_base_framework.framework_output,
 125                         "sharedfp_individual_write_metadata_file: Buff recordlength %ld\n",buff.recordlength);
 126             opal_output(ompi_sharedfp_base_framework.framework_output,
 127                         "sharedfp_individual_write_metadata_file: Size of buff %ld\n",sizeof(buff));
 128         }
 129 
 130         headnode->next = current->next;
 131         free(current);
 132         current = (headnode)->next;
 133 
 134         /*Write to the metadata file*/
 135 
 136         ret = mca_common_ompio_file_write_at ( (headnode)->metadatafilehandle,
 137                                                (headnode)->metadatafile_offset,
 138                                                &buff,32, MPI_BYTE, &status);
 139         if ( OMPI_SUCCESS != ret ) {
 140             goto exit;
 141         }
 142         (headnode)->numofrecordsonfile = headnode->numofrecordsonfile + 1;
 143         (headnode)->metadatafile_offset = (headnode)->metadatafile_offset + sizeof(buff);
 144     }
 145 
 146     /*All records are being read from the linked list and written to the file*/
 147     (headnode)->numofrecords = 0;
 148 
 149 exit:
 150     return ret;
 151 }

/* [<][>][^][v][top][bottom][index][help] */