• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/genericProc/programs/MTGL/mtgl/snap_util.h

Go to the documentation of this file.
00001 /*  _________________________________________________________________________
00002  *
00003  *  MTGL: The MultiThreaded Graph Library
00004  *  Copyright (c) 2008 Sandia Corporation.
00005  *  This software is distributed under the BSD License.
00006  *  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00007  *  the U.S. Government retains certain rights in this software.
00008  *  For more information, see the README file in the top MTGL directory.
00009  *  _________________________________________________________________________
00010  */
00011 
00012 /****************************************************************************/
00013 /*! \file snap_util.h
00014 
00015     \brief Serial implementation of snapshot functions for use on Linux/Mac.
00016 
00017     \author Karen Devine (kddevin@sandia.gov)
00018 
00019     \date 5/6/2009
00020 */
00021 /****************************************************************************/
00022 
00023 #ifndef MTGL_SNAP_UTIL_H
00024 #define MTGL_SNAP_UTIL_H
00025 
00026 // Don't use these stubs if actually working on the MTA/XMT.
00027 #ifdef __MTA__
00028 
00029 #include <luc/luc_exported.h>
00030 #include <snapshot/client.h>
00031 
00032 #else
00033 
00034 #include <cstdio>
00035 #include <cassert>
00036 #include <cfloat>
00037 #include <climits>
00038 #include <cstdlib>
00039 #include <iostream>
00040 
00041 // For windows compatibility (within Titan)
00042 #ifndef WIN32
00043   #include <stdint.h>
00044 #endif
00045 
00046 #if defined(sun) || defined(__sun)
00047 typedef uint64_t u_int64_t;
00048 #endif
00049 
00050 // Return types and data types used by SNAP
00051 #include <sys/types.h>
00052 #include <sys/stat.h>
00053 
00054 typedef int luc_error_t;
00055 typedef uint64_t luc_endpoint_id_t;
00056 typedef struct stat snap_stat_buf;
00057 
00058 // ERROR CODES RETURNED BY SNAP
00059 #define LUC_ERR_OK 1
00060 #define SNAP_ERR_OK 1
00061 #define LUC_ERR_TIMEOUT -13
00062 #define SNAP_ERR_BAD_PARAMETER 2
00063 #define SNAP_ERR_OPEN_FAILED 3
00064 #define SNAP_ERR_READ_FAILED 4
00065 #define SNAP_ERR_RESOURCE_FAILURE 5
00066 #define SNAP_ERR_RESTORE_FAILED 6
00067 #define SNAP_ERR_SNAPSHOT_FAILED 7
00068 #define SNAP_ERR_WRITE_FAILED 8
00069 
00070 namespace mtgl {
00071 
00072 /// Initializes the snapshot system; we don't have to do anything.
00073 inline luc_error_t snap_init()
00074 {
00075   return SNAP_ERR_OK;
00076 }
00077 
00078 /// Writes contents of buffer buf to file fname.
00079 inline luc_error_t snap_snapshot(
00080   char fname[],
00081   void *buf,
00082   size_t count,
00083   int64_t *err)
00084 {
00085   FILE *fp = fopen(fname, "w");
00086 
00087   if (fp == NULL)
00088   {
00089     fprintf(stderr, "ERROR in snap_snapshot:  File %s not found\n", fname);
00090 
00091     if (err != NULL) *err = -1;
00092 
00093     return SNAP_ERR_SNAPSHOT_FAILED;
00094   }
00095 
00096   fwrite(buf, 1, count, fp);
00097   fclose(fp);
00098 
00099   if (err != NULL) *err = 0;
00100 
00101   return SNAP_ERR_OK;
00102 }
00103 
00104 /// Reads contents of file fname into buffer buf.
00105 inline luc_error_t snap_restore(
00106   char fname[],
00107   void *buf,
00108   size_t count,
00109   int64_t *err)
00110 {
00111   FILE *fp = fopen(fname, "r");
00112 
00113   if (fp == NULL)
00114   {
00115     fprintf(stderr, "ERROR in snap_restore:  File %s not found\n", fname);
00116 
00117     if (err != NULL) *err = -1;
00118 
00119     return SNAP_ERR_RESTORE_FAILED;
00120   }
00121 
00122   if (fread(buf, 1, count, fp) == 0)
00123   {
00124     return SNAP_ERR_RESTORE_FAILED;
00125   }
00126 
00127   fclose(fp);
00128 
00129   if (err != NULL) *err = 0;
00130 
00131   return SNAP_ERR_OK;
00132 }
00133 
00134 /// Stub not yet implemented since it is not yet used in MTGL.
00135 inline luc_error_t snap_pwrite(
00136   char fname[],
00137   luc_endpoint_id_t swEP,
00138   const void *buf,
00139   size_t count,
00140   off_t offset,
00141   int64_t *err)
00142 {
00143   fprintf(stderr, "ERROR:  snap_pwrite not yet implemented.\n");
00144 
00145   if (err != NULL) *err = -1;
00146 
00147   return SNAP_ERR_WRITE_FAILED;
00148 }
00149 
00150 /// Stub not yet implemented since it is not yet used in MTGL.
00151 inline luc_error_t snap_pread(
00152   char fname[],
00153   luc_endpoint_id_t swEP,
00154   void *buf,
00155   size_t count,
00156   off_t offset,
00157   int64_t *err)
00158 {
00159   fprintf(stderr, "ERROR:  snap_pread not yet implemented.\n");
00160 
00161   if (err != NULL) *err = -1;
00162 
00163   return SNAP_ERR_READ_FAILED;
00164 }
00165 
00166 /// \brief Returns info about a file.
00167 ///
00168 /// We typedef snap_stat_buf to be of type struct stat; the two structs have
00169 /// similar fields and, in particular, share the st_size field used in MTGL.
00170 inline luc_error_t snap_stat(
00171   char  fname[],
00172   luc_endpoint_id_t swEP,
00173   snap_stat_buf *statBuf,
00174   int64_t *err)
00175 {
00176   int tmp = stat(fname, statBuf);
00177 
00178   if (err != NULL) *err = tmp;
00179 
00180   return SNAP_ERR_OK;
00181 }
00182 
00183 }
00184 
00185 #endif
00186 
00187 #endif

Generated on Fri Oct 22 2010 11:02:23 for SST by  doxygen 1.7.1