GraphChi  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros
graphchi_context.hpp
Go to the documentation of this file.
1 
2 
3 
32 #ifndef DEF_GRAPHCHI_CONTEXT
33 #define DEF_GRAPHCHI_CONTEXT
34 
35 #include <vector>
36 #include <assert.h>
37 #include <omp.h>
38 #include <sys/time.h>
39 
40 #include "graphchi_types.hpp"
41 #include "api/ischeduler.hpp"
42 
43 namespace graphchi {
44 
46 
47  size_t nvertices;
48  ischeduler * scheduler;
49  int iteration;
50  int num_iterations;
51  int last_iteration;
52  int execthreads;
53  std::vector<double> deltas;
54  timeval start;
55  std::string filename;
56 
57  graphchi_context() : scheduler(NULL), iteration(0), last_iteration(-1) {
58  gettimeofday(&start, NULL);
59  }
60 
61  double runtime() {
62  timeval end;
63  gettimeofday(&end, NULL);
64  return end.tv_sec-start.tv_sec+ ((double)(end.tv_usec-start.tv_usec))/1.0E6;
65  }
66 
70  void set_last_iteration(int _last_iteration) {
71  last_iteration = _last_iteration;
72  }
73 
74  void reset_deltas(int nthreads) {
75  deltas = std::vector<double>(nthreads, 0.0);
76  }
77 
78  double get_delta() {
79  double d = 0.0;
80  for(int i=0; i < (int)deltas.size(); i++) {
81  d += deltas[i];
82  }
83  return d;
84  }
85 
86  inline bool isnan(double x) {
87  return !(x<0 || x>=0);
88  }
89 
96  void log_change(double delta) {
97  deltas[omp_get_thread_num()] += delta;
98  assert(delta >= 0);
99  assert(!isnan(delta)); /* Sanity check */
100  }
101  };
102 
103 }
104 
105 
106 #endif
107