diff --git a/configure b/configure index 47353da2..0e5aa2c6 100755 --- a/configure +++ b/configure @@ -517,13 +517,13 @@ echo -n 'Checking if OpenMP is provided... ' if testopenmp; then echo 'OpenMP works.' else - OLDFLAGS=$LDFLAGS - LDFLAGS="$LDFLAGS -fopenmp" + OCXXFLAGS=$CXXFLAGS + CXXFLAGS="$CXXFLAGS -fopenmp" if testopenmp; then echo 'using OpenMP via -fopenmp flag.' else echo 'Uuable to compile OpenMP test program, will build without OpenMP, to enable OpenMP please provide e.g. CXXFLAGS=-fopenmp.' - LDFLAGS="$OLDFLAGS -DOMP_OFF" + CXXFLAGS="$OCXXFLAGS -DOMP_OFF" fi fi diff --git a/examples/apsp.cxx b/examples/apsp.cxx index 1b3dc2cd..7c7a9183 100644 --- a/examples/apsp.cxx +++ b/examples/apsp.cxx @@ -57,7 +57,7 @@ int apsp(int n, [](void * a, void * b, int * n, MPI_Datatype*){ for (int i=0; i<*n; i++){ if (((path*)a)[i].w <= ((path*)b)[i].w) - ((path*)b)[0] = ((path*)a)[0]; + ((path*)b)[i] = ((path*)a)[i]; } }, 1, &opath); diff --git a/examples/btwn_central.cxx b/examples/btwn_central.cxx index 90c2ead0..9c3423a8 100644 --- a/examples/btwn_central.cxx +++ b/examples/btwn_central.cxx @@ -7,56 +7,59 @@ #include #include -using namespace CTF; +using namespace CTF; //structure for regular path that keeps track of the multiplicity of paths -class path { +class mpath { public: int w; // weighted distance int m; // multiplictiy - path(int w_, int m_){ w=w_; m=m_; } - path(path const & p){ w=p.w; m=p.m; } - path(){}; + mpath(int w_, int m_){ w=w_; m=m_; } + mpath(mpath const & p){ w=p.w; m=p.m; } + mpath(){}; }; -//(min, +) tropical semiring for path structure -Semiring get_path_semiring(){ - //struct for path with w=path weight, h=#hops - MPI_Op opath; +//path with a centrality score +class cpath : public mpath { + public: + double c; // centrality score + cpath(int w_, int m_, double c_) : mpath(w_, m_) { c=c_;} + cpath(cpath const & p) : mpath(p) { c=p.c; } + cpath(){}; +}; + + +//(min, +) tropical semiring for mpath structure +Semiring get_mpath_semiring(){ + //struct for mpath with w=mpath weight, h=#hops + MPI_Op ompath; MPI_Op_create( [](void * a, void * b, int * n, MPI_Datatype*){ for (int i=0; i<*n; i++){ - if (((path*)a)[i].w <= ((path*)b)[i].w){ - ((path*)b)[0] = ((path*)a)[0]; + if (((mpath*)a)[i].w < ((mpath*)b)[i].w){ + ((mpath*)b)[i] = ((mpath*)a)[i]; + } else if (((mpath*)a)[i].w == ((mpath*)b)[i].w){ + ((mpath*)b)[i].m += ((mpath*)a)[i].m; } } }, - 1, &opath); + 1, &ompath); //tropical semiring with hops carried by winner of min - Semiring p(path(INT_MAX/2,1), - [](path a, path b){ + Semiring p(mpath(INT_MAX/2,1), + [](mpath a, mpath b){ if (a.w get_cpath_monoid(){ //struct for cpath with w=cpath weight, h=#hops @@ -65,8 +68,11 @@ Monoid get_cpath_monoid(){ MPI_Op_create( [](void * a, void * b, int * n, MPI_Datatype*){ for (int i=0; i<*n; i++){ - if (((cpath*)a)[i].w <= ((cpath*)b)[i].w){ - ((cpath*)b)[0] = ((cpath*)a)[0]; + if (((cpath*)a)[i].w > ((cpath*)b)[i].w){ + ((cpath*)b)[i] = ((cpath*)a)[i]; + } else if (((cpath*)a)[i].w == ((cpath*)b)[i].w){ + ((cpath*)b)[i].m += ((cpath*)a)[i].m; + ((cpath*)b)[i].c += ((cpath*)a)[i].c; } } }, @@ -82,11 +88,11 @@ Monoid get_cpath_monoid(){ return cp; } -//overwrite printfs to make it possible to print matrices of paths +//overwrite printfs to make it possible to print matrices of mpaths namespace CTF { template <> - inline void Set::print(char const * a, FILE * fp) const { - fprintf(fp,"(w=%d m=%d)",((path*)a)[0].w,((path*)a)[0].m); + inline void Set::print(char const * a, FILE * fp) const { + fprintf(fp,"(w=%d m=%d)",((mpath*)a)[0].w,((mpath*)a)[0].m); } template <> inline void Set::print(char const * a, FILE * fp) const { @@ -104,37 +110,37 @@ void btwn_cnt_fast(Matrix A, int b, Vector & v){ World dw = *A.wrld; int n = A.nrow; - Semiring p = get_path_semiring(); + Semiring p = get_mpath_semiring(); Monoid cp = get_cpath_monoid(); for (int ib=0; ib)([=](int& w){ w = 0; }))(A["ii"]); Tensor iA = A.slice(ib*n, (ib+k-1)*n+n-1); ((Transform)([=](int& w){ w = INT_MAX/2; }))(A["ii"]); - //let shortest paths vectors be paths - Matrix B(n, k, dw, p, "B"); - B["ij"] = ((Function)([](int w){ return path(w, 1); }))(iA["ij"]); + //let shortest mpaths vectors be mpaths + Matrix B(n, k, dw, p, "B"); + B["ij"] = ((Function)([](int w){ return mpath(w, 1); }))(iA["ij"]); //compute Bellman Ford for (int i=0; i)([](int w, path p){ return path(p.w+w, p.m); }))(A["ik"],B["kj"]); - B["ij"] += ((Function)([](int w){ return path(w, 1); }))(iA["ij"]); + B["ij"] = ((Function)([](int w, mpath p){ return mpath(p.w+w, p.m); }))(A["ik"],B["kj"]); + B["ij"] += ((Function)([](int w){ return mpath(w, 1); }))(iA["ij"]); } - //transfer shortest path data to Matrix of cpaths to compute c centrality scores + //transfer shortest mpath data to Matrix of cpaths to compute c centrality scores Matrix cB(n, k, dw, cp, "cB"); - ((Transform)([](path p, cpath & cp){ cp = cpath(p.w, p.m, 0.); }))(B["ij"],cB["ij"]); + ((Transform)([](mpath p, cpath & cp){ cp = cpath(p.w, p.m, 0.); }))(B["ij"],cB["ij"]); //compute centrality scores by propagating them backwards from the furthest nodes (reverse Bellman Ford) for (int i=0; i)( [](int w, cpath p){ return cpath(p.w-w, p.m, (1.+p.c)/p.m); }))(A["ki"],cB["kj"]); - ((Transform)([](path p, cpath & cp){ + ((Transform)([](mpath p, cpath & cp){ cp = (p.w <= cp.w) ? cpath(p.w, p.m, cp.c*p.m) : cpath(p.w, p.m, 0.); }))(B["ij"],cB["ij"]); } @@ -157,39 +163,39 @@ void btwn_cnt_naive(Matrix & A, Vector & v){ World dw = *A.wrld; int n = A.nrow; - Semiring p = get_path_semiring(); + Semiring p = get_mpath_semiring(); Monoid cp = get_cpath_monoid(); - //path matrix to contain distance matrix - Matrix P(n, n, dw, p, "P"); + //mpath matrix to contain distance matrix + Matrix P(n, n, dw, p, "P"); - Function setw([](int w){ return path(w, 1); }); + Function setw([](int w){ return mpath(w, 1); }); P["ij"] = setw(A["ij"]); - ((Transform)([=](path& w){ w = path(INT_MAX/2, 1); }))(P["ii"]); + ((Transform)([=](mpath& w){ w = mpath(INT_MAX/2, 1); }))(P["ii"]); - Matrix Pi(n, n, dw, p); + Matrix Pi(n, n, dw, p); Pi["ij"] = P["ij"]; - //compute all shortest paths by Bellman Ford + //compute all shortest mpaths by Bellman Ford for (int i=0; i)([=](path & p){ p = path(0,1); }))(P["ii"]); + ((Transform)([=](mpath & p){ p = mpath(0,1); }))(P["ii"]); P["ij"] = Pi["ik"]*P["kj"]; } - ((Transform)([=](path& p){ p = path(INT_MAX/2, 1); }))(P["ii"]); + ((Transform)([=](mpath& p){ p = mpath(INT_MAX/2, 1); }))(P["ii"]); int lenn[3] = {n,n,n}; Tensor postv(3, lenn, dw, cp, "postv"); - //set postv_ijk = shortest path from i to k (d_ik) - postv["ijk"] += ((Function)([](path p){ return cpath(p.w, p.m, 0.0); }))(P["ik"]); + //set postv_ijk = shortest mpath from i to k (d_ik) + postv["ijk"] += ((Function)([](mpath p){ return cpath(p.w, p.m, 0.0); }))(P["ik"]); //set postv_ijk = - // for all nodes j on the shortest path from i to k (d_ik=d_ij+d_jk) - // let multiplicity of shortest paths from i to j is a, from j to k is b, and from i to k is c + // for all nodes j on the shortest mpath from i to k (d_ik=d_ij+d_jk) + // let multiplicity of shortest mpaths from i to j is a, from j to k is b, and from i to k is c // then postv_ijk = a*b/c - ((Transform)( - [=](path a, path b, cpath & c){ + ((Transform)( + [=](mpath a, mpath b, cpath & c){ if (c.wisequal(alpha,sr_A->mulid())){ for (int i=imin; iel_size]; func->acc_f(A+offsets_A[0][i], B+offsets_B[0][i], C+offsets_C[0][i], diff --git a/src/shared/model.cxx b/src/shared/model.cxx index 8772ee63..e862c42d 100644 --- a/src/shared/model.cxx +++ b/src/shared/model.cxx @@ -363,11 +363,11 @@ namespace CTF_int { } } - static double * get_cube_param(double const * param, int nparam){ + /*static double * get_cube_param(double const * param, int nparam){ double * lparam = new double[nparam*(nparam+1)*(nparam+2)/6+nparam*(nparam+1)/2+nparam]; cube_params(param, lparam, nparam); return lparam; - } + }*/ template diff --git a/src/summation/spr_seq_sum.cxx b/src/summation/spr_seq_sum.cxx index 86205fd9..b10f86d4 100644 --- a/src/summation/spr_seq_sum.cxx +++ b/src/summation/spr_seq_sum.cxx @@ -105,8 +105,9 @@ namespace CTF_int{ univar_function const * func){ TAU_FSTART(spA_dnB_seq_sum); if (order_B == 0){ - if (!sr_B->isequal(beta, sr_B->mulid())) + if (!sr_B->isequal(beta, sr_B->mulid())){ sr_B->mul(beta, B, B); + } ConstPairIterator pi(sr_A, A); for (int64_t i=0; iel_size]; @@ -123,11 +124,12 @@ namespace CTF_int{ } } else { int64_t sz_B = sy_packed_size(order_B, edge_len_B, sym_B); - if (!sr_B->isequal(beta, sr_B->mulid())) + if (!sr_B->isequal(beta, sr_B->mulid())){ if (sr_B->isequal(beta, sr_B->addid()) || sr_B->isequal(beta, NULL)) sr_B->set(B, sr_B->addid(), sz_B); else sr_B->scal(sz_B, beta, B, 1); + } int64_t lda_B[order_B]; for (int i=0; i