COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2//@HEADER
3// *****************************************************************************
4//
5// HPCGraph: Graph Computation on High Performance Computing Systems
6// Copyright (2016) Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact George M. Slota (gmslota@sandia.gov)
39// Siva Rajamanickam (srajama@sandia.gov)
40// Kamesh Madduri (madduri@cse.psu.edu)
41//
42// *****************************************************************************
43//@HEADER
44*/
45
46#include <mpi.h>
47#include <omp.h>
48#include <time.h>
49#include <getopt.h>
50#include <string.h>
51#include <iostream>
52
53using namespace std;
54
57
58#include "dist_graph.h"
59#include "comms.h"
60#include "io_pp.h"
61#include "wcc.h"
62#include "scc.h"
63#include "pagerank.h"
64#include "labelprop.h"
65#include "harmonic.h"
66#include "kcore.h"
67
68void print_usage(char** argv)
69{
70 printf("To run: %s [graphfile] [options]\n", argv[0]);
71 printf("\t Use -h for list of options\n\n");
72}
73
74void print_usage_full(char** argv)
75{
76 printf("To run: %s [graphfile] [options]\n\n", argv[0]);
77 printf("Options:\n");
78 printf("\t-a\n");
79 printf("\t\tRun all analytics\n");
80 printf("\t-w\n");
81 printf("\t\tRun weakly connected components\n");
82 printf("\t-s\n");
83 printf("\t\tRun strongly connected components\n");
84 printf("\t-l\n");
85 printf("\t\tRun label propagation\n");
86 printf("\t-p\n");
87 printf("\t\tRun PageRank\n");
88 printf("\t-c\n");
89 printf("\t\tRun harmonic centrality\n");
90 printf("\t-k\n");
91 printf("\t\tRun approximate k-core\n");
92 printf("\t-o [outfile]\n");
93 printf("\t\tAdjust output file [default: 'out.algorithm']\n");
94 printf("\t-i [comma separated input vertex id list]\n");
95 printf("\t\tVertex ids to analyze for harmonic centrality [default: none]\n");
96 printf("\t-p [part file]\n");
97 printf("\t\tPartition file to use for mapping vertices to tasks\n");
98 printf("\t-t [#]\n");
99 printf("\t\tAdjust iteration count for label prop, PageRank, k-core [default: 20]\n");
100 printf("\t-f\n");
101 printf("\t\tRun verification routines\n");
102 printf("\t-v\n");
103 printf("\t\tRun verification routines\n");
104 printf("\t-d\n");
105 printf("\t\tRun verification routines\n");
106}
107
108
109int main(int argc, char **argv)
110{
111 srand(time(0));
112 setbuf(stdout, 0);
113
114 verbose = false;
115 debug = false;
116 verify = false;
117 output = false;
118
119 MPI_Init(&argc, &argv);
120 MPI_Comm_rank(MPI_COMM_WORLD, &procid);
121 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
122
123 if (argc < 2)
124 {
125 if (procid == 0) print_usage(argv);
126 MPI_Barrier(MPI_COMM_WORLD);
127 MPI_Abort(MPI_COMM_WORLD, 1);
128 }
129
130 char* input_filename = strdup(argv[1]);
131
132 bool run_wcc = false;
133 bool run_scc = false;
134 bool run_pagerank = false;
135 bool run_labelprop = false;
136 bool run_harmonic_centrality = false;
137 bool run_degree_centrality = false;
138 bool run_kcore = false;
139 bool run_approx_kcore = false;
140
141 uint32_t num_iter = 20;
142 uint64_t num_to_output = 0;
143 char* output_file = NULL;
144 char* temp_out = NULL;
145 char* input_list_str = NULL;
146 uint64_t* input_list = NULL;
147 char* part_list = NULL;
148 char c;
149 optind++; // this is missing. without this getopt treats the filename as an option
150 while ((c = getopt (argc, argv, "awsrlckt:n:p:o:i:hfvd")) != -1) {
151 switch (c) {
152 case 'a':
153 run_wcc = true;
154 run_scc = true;
155 run_pagerank = true;
156 run_labelprop = true;
157 run_harmonic_centrality = true;
158 run_kcore = true;
159 break;
160 case 'w': run_wcc = true;break;
161 case 's': run_scc = true; break;
162 case 'r': run_pagerank = true; break;
163 case 'l': run_labelprop = true; break;
164 case 'c': run_harmonic_centrality = true; break;
165 case 'k': run_kcore = true; break;
166 case 'f': verify = true; break;
167 case 'v': verbose = true; break;
168 case 'd': debug = true; break;
169 //case 'd': offset_vids = true; break;
170 case 't':
171 num_iter = strtoul(optarg, NULL, 10); break;
172 run_approx_kcore = true;
173 case 'p':
174 part_list = (char*)malloc((strlen(optarg)+8)*sizeof(char));
175 part_list[0] = '\0';
176 strcat(part_list, optarg);
177 break;
178 case 'o':
179 output = true;
180 output_file = (char*)malloc((strlen(optarg)+128)*sizeof(char));
181 output_file[0] = '\0';
182 strcat(output_file, optarg);
183 break;
184 case 'i':
185 input_list_str = (char*)malloc((strlen(optarg)+8)*sizeof(char));
186 input_list_str[0] = '\0';
187 strcat(input_list_str, optarg);
188 break;
189 case 'h':
190 if (procid == 0) print_usage_full(argv);
191 MPI_Barrier(MPI_COMM_WORLD);
192 MPI_Abort(MPI_COMM_WORLD, 1);
193 break;
194 default:
195 throw_err("Input argument format error, use '-h' for options");
196 }
197 }
198
200 dist_graph_t g;
201 mpi_data_t comm;
203
204 init_comm_data(&comm);
205 load_graph_edges_64(input_filename, &ggi);
206
207 if (nprocs > 1)
208 {
209 exchange_out_edges(&ggi, &comm);
210 exchange_in_edges(&ggi, &comm);
211 create_graph(&ggi, &g);
212 relabel_edges(&g);
213 if (part_list != NULL)
214 repart_graph(&g, &comm, part_list);
215 }
216 else
217 {
218 create_graph_serial(&ggi, &g);
219 }
221 init_queue_data(&g, &q);
222
223 if (input_list_str != NULL)
224 {
225 input_list = str_to_array(input_list_str, &num_to_output);
226 }
227 else
228 {
229 num_to_output = 1;
230 input_list = (uint64_t*)malloc(1*sizeof(uint64_t));
231 input_list[0] = g.max_degree_vert;
232 }
233 if (num_to_output < 0)
234 num_to_output = g.n;
235 if (output_file == NULL)
236 output_file = strdup("out");
237 temp_out = (char*)malloc((strlen(output_file)+128)*sizeof(char));
238
239 if (run_wcc)
240 {
241 temp_out[0] = '\0';
242 strcat(temp_out, output_file);
243 strcat(temp_out, ".wcc");
244 wcc_dist(&g, &comm, &q, g.max_degree_vert, temp_out);
245 }
246 if (run_scc)
247 {
248 temp_out[0] = '\0';
249 strcat(temp_out, output_file);
250 strcat(temp_out, ".scc");
251 scc_dist(&g, &comm, &q, g.max_degree_vert, temp_out);
252 }
253 if (run_pagerank)
254 {
255 temp_out[0] = '\0';
256 strcat(temp_out, output_file);
257 strcat(temp_out, ".pagerank");
258 pagerank_dist(&g, &comm, num_iter, temp_out);
259 }
260 if (run_labelprop)
261 {
262 temp_out[0] = '\0';
263 strcat(temp_out, output_file);
264 strcat(temp_out, ".labelprop");
265 labelprop_dist(&g, &comm, num_iter, temp_out);
266 }
267 if (run_harmonic_centrality)
268 {
269 temp_out[0] = '\0';
270 strcat(temp_out, output_file);
271 strcat(temp_out, ".harmonic");
272 harmonic_dist(&g, &comm, &q, temp_out, num_to_output, input_list);
273 }
274 if (run_kcore)
275 {
276 temp_out[0] = '\0';
277 strcat(temp_out, output_file);
278 strcat(temp_out, ".kcore");
279 kcore_dist(&g, &comm, &q, num_iter, temp_out, run_approx_kcore);
280 }
281
282
283 clear_graph(&g);
284 clear_comm_data(&comm);
286 free(input_filename);
287 free(temp_out);
288 free(output_file);
289 if (input_list != NULL)
290 free(input_list);
291 if (input_list_str != NULL)
292 free(input_list_str);
293
294 MPI_Barrier(MPI_COMM_WORLD);
295 MPI_Finalize();
296
297 return 0;
298}
299
void print_usage_full(char **argv)
Definition main.cpp:74
int procid
Definition main.cpp:55
bool debug
Definition main.cpp:56
bool verify
Definition main.cpp:56
bool verbose
Definition main.cpp:56
void print_usage(char **argv)
Definition main.cpp:68
bool output
Definition main.cpp:56
int nprocs
Definition main.cpp:55
int main()
Definition Driver.cpp:12
Mac OS X ATTR com apple quarantine q
Definition ._remapper.cpp:1
void clear_comm_data(mpi_data_t *comm)
Definition comms.cpp:111
void clear_queue_data(queue_data_t *q)
Definition comms.cpp:75
void init_queue_data(dist_graph_t *g, queue_data_t *q)
Definition comms.cpp:58
void init_comm_data(mpi_data_t *comm)
Definition comms.cpp:84
int clear_graph(dist_graph_t *g)
int repart_graph(dist_graph_t *g, mpi_data_t *comm, char *part_file)
int relabel_edges(dist_graph_t *g)
int create_graph(graph_gen_data_t *ggi, dist_graph_t *g)
int create_graph_serial(graph_gen_data_t *ggi, dist_graph_t *g)
int get_max_degree_vert(dist_graph_t *g)
int harmonic_dist(dist_graph_t *g, mpi_data_t *comm, queue_data_t *q, char *output_file, uint64_t num_to_output, uint64_t *input_list)
Definition harmonic.cpp:200
int load_graph_edges_64(char *input_filename, graph_gen_data_t *ggi)
Definition io_pp.cpp:140
int exchange_in_edges(graph_gen_data_t *ggi, mpi_data_t *comm)
Definition io_pp.cpp:338
int exchange_out_edges(graph_gen_data_t *ggi, mpi_data_t *comm)
Definition io_pp.cpp:212
int kcore_dist(dist_graph_t *g, mpi_data_t *comm, queue_data_t *q, uint32_t num_iter, char *output_file, bool run_approx)
Definition kcore.cpp:329
int run_kcore(dist_graph_t *g, mpi_data_t *comm, queue_data_t *q, uint64_t *kcores, uint32_t num_iter, bool run_approx)
Definition kcore.cpp:64
int labelprop_dist(dist_graph_t *g, mpi_data_t *comm, uint32_t num_iter, char *output_file)
int run_labelprop(dist_graph_t *g, mpi_data_t *comm, uint64_t *&labels, uint32_t num_iter)
Definition labelprop.cpp:67
int pagerank_dist(dist_graph_t *g, mpi_data_t *comm, uint32_t num_iter, char *output_file)
Definition pagerank.cpp:331
int run_pagerank(dist_graph_t *g, mpi_data_t *comm, double *&pageranks, uint32_t num_iter)
Definition pagerank.cpp:65
int scc_dist(dist_graph_t *g, mpi_data_t *comm, queue_data_t *q, uint64_t root, char *output_file)
Definition scc.cpp:738
unsigned int uint32_t
Definition stdint.h:80
uint64_t max_degree_vert
Definition dist_graph.h:71
uint64_t n
Definition dist_graph.h:61
void throw_err(char const *err_message)
Definition util.cpp:58
uint64_t * str_to_array(char *input_list_str, uint64_t *num)
Definition util.cpp:108
int wcc_dist(dist_graph_t *g, mpi_data_t *comm, queue_data_t *q, uint64_t root, char *output_file)
Definition wcc.cpp:427