13 path(
int w_,
int h_){ w=w_; h=h_; }
20 fprintf(fp,
"(%d %d)",((
path*)a)[0].
w,((
path*)a)[0].h);
30 [](
int a,
int b){
return std::min(a,b); },
33 [](
int a,
int b){
return a+
b; });
38 A.fill_random(0, n*n);
48 for (
int i=1; i<n; i=i<<1){
50 D[
"ij"] += D[
"ik"]*D[
"kj"];
57 [](
void * a,
void * b,
int * n, MPI_Datatype*){
58 for (
int i=0; i<*n; i++){
67 [](
path a,
path b){
if (a.
w<b.
w || (a.
w == b.
w && a.
h<b.
h))
return a;
else return b; },
76 P[
"ij"] = setw(A[
"ij"]);
82 for (
int i=1; i<n; i=i<<1){
90 P[
"ij"] += Pi[
"ik"]*P[
"kj"];
96 xtrw(P[
"ij"], D[
"ij"]);
100 D2.
sparsify([](
int w){
return w!=0; });
106 int pass = (loc_nnz == 0);
109 MPI_Reduce(MPI_IN_PLACE, &pass, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
111 printf(
"{ APSP by path doubling } passed \n");
113 printf(
"{ APSP by path doubling } failed \n");
115 MPI_Reduce(&pass, MPI_IN_PLACE, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
119 printf(
"Starting %d benchmarking iterations of dense APSP-PD...\n", niter);
121 double min_time = DBL_MAX;
122 double max_time = 0.0;
123 double tot_time = 0.0;
127 for (
int i=0; i<niter; i++){
129 double start_time = MPI_Wtime();
130 for (
int j=1; j<n; j=j<<1){
131 D[
"ij"] += D[
"ik"]*D[
"kj"];
133 double end_time = MPI_Wtime();
134 double iter_time = end_time-start_time;
135 times[i] = iter_time;
136 tot_time += iter_time;
137 if (iter_time < min_time) min_time = iter_time;
138 if (iter_time > max_time) max_time = iter_time;
143 printf(
"Completed %d benchmarking iterations of dense APSP-PD (n=%d).\n", niter, n);
144 printf(
"All iterations times: ");
145 for (
int i=0; i<niter; i++){
146 printf(
"%lf ", times[i]);
149 std::sort(times,times+niter);
150 printf(
"Dense APSP (n=%d) Min time=%lf, Avg time = %lf, Med time = %lf, Max time = %lf\n",n,min_time,tot_time/niter, times[niter/2], max_time);
153 printf(
"Starting %d benchmarking iterations of sparse APSP-PD...\n", niter);
160 for (
int i=0; i<niter; i++){
163 double start_time = MPI_Wtime();
164 for (
int j=1; j<n; j=j<<1){
167 P[
"ij"] += Pi[
"ik"]*P[
"kj"];
169 double end_time = MPI_Wtime();
170 double iter_time = end_time-start_time;
171 times[i] = iter_time;
172 tot_time += iter_time;
173 if (iter_time < min_time) min_time = iter_time;
174 if (iter_time > max_time) max_time = iter_time;
179 printf(
"Completed %d benchmarking iterations of sparse APSP-PD (n=%d).\n", niter, n);
180 printf(
"All iterations times: ");
181 for (
int i=0; i<niter; i++){
182 printf(
"%lf ", times[i]);
185 std::sort(times,times+niter);
186 printf(
"Sparse APSP (n=%d): Min time=%lf, Avg time = %lf, Med time = %lf, Max time = %lf\n",n,min_time,tot_time/niter, times[niter/2], max_time);
198 char ** itr = std::find(begin, end, option);
199 if (itr != end && ++itr != end){
206 int main(
int argc,
char ** argv){
207 int rank,
np, n, pass, niter;
208 int const in_num = argc;
209 char ** input_str = argv;
211 MPI_Init(&argc, &argv);
212 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
213 MPI_Comm_size(MPI_COMM_WORLD, &np);
216 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
220 if (
getCmdOption(input_str, input_str+in_num,
"-niter")){
221 niter = atof(
getCmdOption(input_str, input_str+in_num,
"-niter"));
222 if (niter < 0) niter = 10;
226 World dw(argc, argv);
229 printf(
"Computing APSP of dense graph with %d nodes using dense and sparse path doubling\n",n);
231 pass =
apsp(n, dw, niter);
Matrix class which encapsulates a 2D tensor.
void get_local_pairs(int64_t *npair, Pair< dtype > **pairs, bool nonzeros_only=false, bool unpack_sym=false) const
gives the global indices and values associated with the local data
Semiring is a Monoid with an addition multiplicaton function addition must have an identity and be as...
an instance of the CTF library (world) on a MPI communicator
index-value pair used for tensor data input
int main(int argc, char **argv)
char * getCmdOption(char **begin, char **end, const std::string &option)
int rank
rank of local processor
void print(char const *a, FILE *fp=stdout) const
prints the value
void sparsify()
reduce tensor to sparse format, storing only nonzero data, or data above a specified threshold...
epoch during which to measure timers
int apsp(int n, World &dw, int niter=0)