-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraph_ckio.cpp
More file actions
114 lines (106 loc) · 2.76 KB
/
Copy pathgraph_ckio.cpp
File metadata and controls
114 lines (106 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "graph_ckio.decl.h"
#include <iostream>
#include <sys/stat.h>
#include <cmath>
#include <stdio.h>
#include <map>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <limits>
#include <sys/stat.h>
CProxy_Main mainProxy;
int N; // number of processors
int V; // number of vertices
int imax; // integer maximum
std::string global_fname;
void read_graph_file(Ck::IO::Session session, std::string fname)
{
Ck::IO::FileReader fr(session);
std::string readbuf;
std::string delim = ",";
CkVec<LongEdge> edges;
int max_index = 0;
while(!fr.eof())
{
Ck::IO::getline(fr, readbuf);
// get nodes on each edge
std::string token = readbuf.substr(0, readbuf.find(delim));
std::string token2 = readbuf.substr(readbuf.find(delim) + 1, readbuf.length());
// make random distance
int edge_distance = rand() % 10 + 1;
// string to int
int node_num = std::stoi(token);
int node_num_2 = std::stoi(token2);
//ckout << "Edge begin " << node_num << " Edge end " << node_num_2 << " Edge length " << edge_distance << endl;
// find the maximum vertex index
if (node_num > max_index)
max_index = node_num;
if (node_num_2 > max_index)
max_index = node_num_2;
LongEdge new_edge;
new_edge.begin = node_num;
new_edge.end = node_num_2;
new_edge.distance = edge_distance;
edges.insertAtEnd(new_edge);
// ckout << "One loop iteration complete" << endl;
}
CkEnforce(fr.eof());
};
class Main : public CBase_Main
{
Main_SDAG_CODE
private:
// int not_returned;
double start_time;
double read_time;
int max_index;
std::string file_name;
int file_size;
Ck::IO::Session session;
Ck::IO::File f;
struct stat sb;
public:
Main(CkArgMsg *m)
{
N = atoi(m->argv[1]); // read in number of chares
if (!m->argv[1])
{
ckout << "Missing chare count" << endl;
CkExit(0);
}
V = atoi(m->argv[2]); // read in number of vertices
if (!m->argv[2])
{
ckout << "Missing vertex count" << endl;
CkExit(0);
}
file_name = m->argv[3]; // read file name
if (!m->argv[3])
{
ckout << "Missing file name" << endl;
CkExit(0);
}
if(lstat(m->argv[3], &sb) == -1)
{
perror("lstat");
exit(1);
}
file_size = sb.st_size;
int S = atoi(m->argv[4]); // randomize seed
if (!m->argv[4])
{
ckout << "Missing random seed" << endl;
CkExit(0);
}
global_fname = file_name;
mainProxy = thisProxy;
unsigned int seed = (unsigned int)S;
srand(seed);
imax = std::numeric_limits<int>::max();
start_time = CkWallTimer();
thisProxy.run();
delete m;
}
};
#include "graph_ckio.def.h"