COMBINATORIAL_BLAS  1.6
FilteredBFS.cpp
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 #define DETERMINISTIC
30 #include "CombBLAS/CombBLAS.h"
31 #include <mpi.h>
32 #include <sys/time.h>
33 #include <iostream>
34 #include <functional>
35 #include <algorithm>
36 #include <vector>
37 #include <string>
38 #include <sstream>
39 #ifdef THREADED
40  #ifndef _OPENMP
41  #define _OPENMP
42  #endif
43  #include <omp.h>
44 #endif
45 
46 #ifdef USE_PAPI
47  #include <papi.h>
48  #include "papi_combblas_global.h"
49 #endif
50 
51 
52 /* Global variables for timing */
53 
57 
58 /* End global variables */
59 
60 
61 #include "TwitterEdge.h"
62 
63 #define MAX_ITERS 20000
64 #define EDGEFACTOR 16
65 #define ITERS 16
66 #define CC_LIMIT 100
67 #define PERCENTS 4 // testing with 4 different percentiles
68 #define MINRUNS 4
69 //#define ONLYTIME // don't calculate TEPS
70 
71 using namespace std;
72 using namespace combblas;
73 
74 
75 template <typename PARMAT>
76 void Symmetricize(PARMAT & A)
77 {
78  // boolean addition is practically a "logical or"
79  // therefore this doesn't destruct any links
80  PARMAT AT = A;
81  AT.Transpose();
82  A += AT;
83 }
84 
85 
86 #ifdef DETERMINISTIC
87 MTRand GlobalMT(1);
88 #else
89 MTRand GlobalMT; // generate random numbers with Mersenne Twister
90 #endif
91 
92 
93 struct Twitter_obj_randomizer : public std::unary_function<TwitterEdge, TwitterEdge>
94 {
95  const TwitterEdge operator()(const TwitterEdge & x) const
96  {
97  short mycount = 1;
98  bool myfollow = 0;
99  time_t mylatest = static_cast<int64_t>(GlobalMT.rand() * 10000); // random.randrange(0,10000)
100 
101  return TwitterEdge(mycount, myfollow, mylatest);
102  }
103 };
104 
105 struct Twitter_materialize: public std::binary_function<TwitterEdge, time_t, bool>
106 {
107  bool operator()(const TwitterEdge & x, time_t sincedate) const
108  {
109  if(x.isRetwitter() && x.LastTweetBy(sincedate))
110  return false; // false if the edge is going to be kept
111  else
112  return true; // true if the edge is to be pruned
113  }
114 };
115 
116 #ifdef USE_PAPI
117 void CheckPAPI(int errorcode, char [] errorstring)
118 {
119  if (errorcode != PAPI_OK)
120  {
121  PAPI_perror(errorcode, errorstring, PAPI_MAX_STR_LEN);
122  fprintf(stderr, "PAPI error (%d): %s\n", errorcode, errorstring);
123  }
124 }
125 #endif
126 
127 
128 
129 int main(int argc, char* argv[])
130 {
131  int nprocs, myrank;
132 #ifdef _OPENMP
133  int cblas_splits = omp_get_max_threads();
134  int provided, flag, claimed;
135  MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided );
136  MPI_Is_thread_main( &flag );
137  if (!flag)
138  SpParHelper::Print("This thread called init_thread but Is_thread_main gave false\n");
139  MPI_Query_thread( &claimed );
140  if (claimed != provided)
141  SpParHelper::Print("Query thread gave different thread level than requested\n");
142 #else
143  MPI_Init(&argc, &argv);
144  int cblas_splits = 1;
145 #endif
146 
147  MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
148  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
149  int MAXTRIALS;
150  int retval;
151 
152 #ifdef USE_PAPI
153  /* Initialize the PAPI library */
154  retval = PAPI_library_init(PAPI_VER_CURRENT);
155  if (retval != PAPI_VER_CURRENT && retval > 0)
156  {
157  fprintf(stderr,"PAPI library version mismatch!\en");
158  exit(1);
159  }