HavoqGT
havoqgt::parallel_edge_list_reader Class Reference

#include <parallel_edge_list_reader.hpp>

Classes

class  input_iterator_type
 InputIterator class for rmat_edge_generator. More...
 

Public Types

typedef uint64_t vertex_descriptor
 
typedef std::pair< uint64_t, uint64_t > edge_type
 

Public Member Functions

 parallel_edge_list_reader (const std::vector< std::string > &filenames)
 
input_iterator_type begin ()
 Returns the begin of the input iterator. More...
 
input_iterator_type end ()
 Returns the end of the input iterator. More...
 
uint64_t max_vertex_id ()
 
size_t size ()
 

Protected Member Functions

bool try_read_edge (edge_type &edge)
 
void open_files ()
 

Protected Attributes

std::vector< std::string > m_local_filenames
 
std::deque< std::ifstream * > m_ptr_ifstreams
 
uint64_t m_local_edge_count
 
uint64_t m_global_max_vertex
 

Detailed Description

Parallel edge list reader

Definition at line 69 of file parallel_edge_list_reader.hpp.

Member Typedef Documentation

typedef std::pair<uint64_t, uint64_t> havoqgt::parallel_edge_list_reader::edge_type

Definition at line 73 of file parallel_edge_list_reader.hpp.

Constructor & Destructor Documentation

havoqgt::parallel_edge_list_reader::parallel_edge_list_reader ( const std::vector< std::string > &  filenames)
inline
Todo:
Add undirected flag

Definition at line 139 of file parallel_edge_list_reader.hpp.

139  {
140  int mpi_rank = havoqgt_env()->world_comm().rank();
141  int mpi_size = havoqgt_env()->world_comm().size();
142  m_local_edge_count = 0;
144 
145  // identify filenames to be read by local rank
146  for(size_t i=0; i<filenames.size(); ++i) {
147  if(i % mpi_size == mpi_rank) {
148  m_local_filenames.push_back(filenames[i]);
149  }
150  }
151 
152  // First pass to calc max vertex and count edges.
153  open_files();
154  std::cout << "files open" << std::endl;
155  edge_type edge;
156  uint64_t local_max_vertex = 0;
157  while(try_read_edge(edge)) {
159  local_max_vertex = std::max(edge.first, local_max_vertex);
160  local_max_vertex = std::max(edge.second, local_max_vertex);
161  }
162  m_global_max_vertex = mpi::mpi_all_reduce(local_max_vertex, std::greater<uint64_t>(), MPI_COMM_WORLD);
163  }
std::pair< uint64_t, uint64_t > edge_type
const communicator & world_comm() const
int size() const
Definition: mpi.hpp:618
T mpi_all_reduce(T in_d, Op in_op, MPI_Comm mpi_comm)
Definition: mpi.hpp:176
int rank() const
Definition: mpi.hpp:619
environment * havoqgt_env()

Here is the call graph for this function:

Member Function Documentation

input_iterator_type havoqgt::parallel_edge_list_reader::begin ( )
inline

Returns the begin of the input iterator.

Definition at line 167 of file parallel_edge_list_reader.hpp.

167  {
168  // Reset and prepare to have readers
169  open_files();
170  return input_iterator_type(this, 0);
171  }

Here is the call graph for this function:

input_iterator_type havoqgt::parallel_edge_list_reader::end ( )
inline

Returns the end of the input iterator.

Definition at line 174 of file parallel_edge_list_reader.hpp.

174  {
175  return input_iterator_type(this, m_local_edge_count);
176  }
uint64_t havoqgt::parallel_edge_list_reader::max_vertex_id ( )
inline
Todo:
implement

Definition at line 179 of file parallel_edge_list_reader.hpp.

179  {
180  return m_global_max_vertex;
181  }

Here is the caller graph for this function:

void havoqgt::parallel_edge_list_reader::open_files ( )
inlineprotected

Definition at line 204 of file parallel_edge_list_reader.hpp.

204  {
205  if(!m_ptr_ifstreams.empty()) {
206  HAVOQGT_ERROR_MSG("m_ptr_ifstreams not empty.");
207  }
208  for(auto itr=m_local_filenames.begin(); itr!=m_local_filenames.end(); ++itr) {
209  std::ifstream* ptr = new std::ifstream(*itr);
210  if(ptr->good()) {
211  m_ptr_ifstreams.push_back(ptr);
212  } else {
213  std::cerr << "Error opening filename: " << *itr;
214  }
215  }
216  }
std::deque< std::ifstream * > m_ptr_ifstreams
#define HAVOQGT_ERROR_MSG(msg)
Definition: error.hpp:62

Here is the caller graph for this function:

size_t havoqgt::parallel_edge_list_reader::size ( )
inline

Definition at line 183 of file parallel_edge_list_reader.hpp.

183  {
184  return m_local_edge_count;
185  }
bool havoqgt::parallel_edge_list_reader::try_read_edge ( edge_type edge)
inlineprotected

Definition at line 189 of file parallel_edge_list_reader.hpp.

189  {
190  std::string line;
191  while(!m_ptr_ifstreams.empty()) {
192  if(std::getline(*(m_ptr_ifstreams.front()), line)) {
193  std::stringstream ssline(line);
194  ssline >> edge.first >> edge.second;
195  return true;
196  } else { //No remaining lines, close file.
197  delete m_ptr_ifstreams.front();
198  m_ptr_ifstreams.pop_front();
199  }
200  }
201  return false;
202  }
std::deque< std::ifstream * > m_ptr_ifstreams

Here is the caller graph for this function:

Member Data Documentation

uint64_t havoqgt::parallel_edge_list_reader::m_global_max_vertex
protected

Definition at line 221 of file parallel_edge_list_reader.hpp.

uint64_t havoqgt::parallel_edge_list_reader::m_local_edge_count
protected

Definition at line 220 of file parallel_edge_list_reader.hpp.

std::vector< std::string > havoqgt::parallel_edge_list_reader::m_local_filenames
protected

Definition at line 218 of file parallel_edge_list_reader.hpp.

std::deque< std::ifstream* > havoqgt::parallel_edge_list_reader::m_ptr_ifstreams
protected

Definition at line 219 of file parallel_edge_list_reader.hpp.


The documentation for this class was generated from the following file: