COMBINATORIAL_BLAS  1.6
FileHeader.h
Go to the documentation of this file.
1 /****************************************************************/
2 /* Parallel Combinatorial BLAS Library (for Graph Computations) */
3 /* version 1.6 -------------------------------------------------*/
4 /* date: 6/15/2017 ---------------------------------------------*/
5 /* authors: Ariful Azad, Aydin Buluc --------------------------*/
6 /****************************************************************/
7 /*
8  Copyright (c) 2010-2017, The Regents of the University of California
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy
11  of this software and associated documentation files (the "Software"), to deal
12  in the Software without restriction, including without limitation the rights
13  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  copies of the Software, and to permit persons to whom the Software is
15  furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included in
18  all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26  THE SOFTWARE.
27  */
28 
29 
30 #ifndef _COMBBLAS_FILE_HEADER_
31 #define _COMBBLAS_FILE_HEADER_
32 
33 #include "CombBLAS.h"
34 
35 namespace combblas {
36 
37 struct HeaderInfo
38 {
39  HeaderInfo():fileexists(false), headerexists(false) {};
40  bool fileexists;
42  uint64_t version;
43  uint64_t objsize;
44  uint64_t format; // 0: binary, 1: ascii
45 
46  uint64_t m;
47  uint64_t n;
48  uint64_t nnz;
49 };
50 
51 // cout's are OK because ParseHeader is run by a single processor only
52 inline HeaderInfo ParseHeader(const std::string & inputname, FILE * & f, int & seeklength)
53 {
54  f = fopen(inputname.c_str(), "rb");
55  HeaderInfo hinfo;
56  memset(&hinfo, 0, sizeof(hinfo));
57  if(!f)
58  {
59  std::cerr << "Problem reading binary input file\n";
60  f = NULL;
61  return hinfo;
62  }
63  char fourletters[5];
64  size_t result = fread(fourletters, sizeof(char), 4, f);
65  fourletters[4] = '\0';
66  if (result != 4) { std::cout << "Error in fread of header, only " << result << " entries read" << std::endl; return hinfo;}
67 
68  if(strcmp(fourletters,"HKDT") != 0)
69  {
70  rewind(f);
71  fclose(f);
72  hinfo.fileexists = true;
73  return hinfo;
74  }
75  else
76  {
77  hinfo.fileexists = true;
78  hinfo.headerexists = true;
79  }
80 
81  size_t results[6];
82  results[0] = fread(&(hinfo.version), sizeof(hinfo.version), 1, f);
83  results[1] = fread(&(hinfo.objsize), sizeof(hinfo.objsize), 1, f);
84  results[2] = fread(&(hinfo.format), sizeof(hinfo.format), 1, f);
85 
86  results[3] = fread(&(hinfo.m), sizeof(hinfo.m), 1, f);
87  results[4] = fread(&(hinfo.n), sizeof(hinfo.n), 1, f);
88  results[5] = fread(&(hinfo.nnz), sizeof(hinfo.nnz), 1, f);
89  if(std::accumulate(results,results+6,0) != 6)
90  {
91  std::cout << "The required 6 fields (version, objsize, format, m,n,nnz) are not read" << std::endl;
92  std::cout << "Only " << std::accumulate(results,results+6,0) << " fields are read" << std::endl;
93  }
94  else
95  {
96  #ifdef DEBUG
97  std::cout << "Version " << hinfo.version << ", object size " << hinfo.objsize << std::endl;
98  std::cout << "Rows " << hinfo.m << ", columns " << hinfo.m << ", nonzeros " << hinfo.nnz << std::endl;
99  #endif
100  }
101 
102  seeklength = 4 + 6 * sizeof(uint64_t);
103  return hinfo;
104 }
105 
106 
107 }
108 #endif
109 
HeaderInfo ParseHeader(const std::string &inputname, FILE *&f, int &seeklength)
Definition: FileHeader.h:52
Definition: CCGrid.h:4