17 assert(undir_A.
symm ==
SH);
18 World dw(MPI_COMM_WORLD);
23 int nosym[] = {
NS,
NS};
37 for (
int i=0; i<nloc; i++){
38 prs[i].
d = prs[i].
k+1.;
43 Semiring<float> max_semiring(0., [](
float a,
float b){
return std::max(a,b); }, MPI_MAX,
44 1.0, [](
float a,
float b){
return a*
b; });
52 v.
sparsify([](
float f){
return f==1.0; });
58 v[
"i"] += A[
"ij"]*v[
"j"];
62 v[
"i"] += (1.+n)*r[
"i"];
63 v.
sparsify([](
float f){
return f==1.0; });
70 w[
"i"] += undir_A[
"ij"]*v[
"j"];
74 z[
"i"] += undir_A[
"ji"]*w[
"j"];
80 v[
"i"] += -1.0*z[
"i"];
82 v.
sparsify([](
float a){
return a > 0.9; });
88 v[
"i"] += undir_A[
"ij"]*v[
"j"];
89 v[
"i"] += undir_A[
"ij"]*v[
"j"];
94 if (undir_A.
wrld->
rank == 0) printf(
"took %d recursive steps\n",nrecurs);
108 printf(
"Found 2-MIS of size %ld\n",s.
nnz_tot);
115 t[
"i"] += A[
"ij"]*s[
"j"];
123 printf(
"Falure: 2-MIS is not 2-independent, nnz = %d!\n",nnz);
131 printf(
"Falure: 2-MIS is not maximal, nnz = %d!\n",nnz);
144 char ** itr = std::find(begin, end, option);
145 if (itr != end && ++itr != end){
152 int main(
int argc,
char ** argv){
155 int const in_num = argc;
156 char ** input_str = argv;
158 MPI_Init(&argc, &argv);
159 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
160 MPI_Comm_size(MPI_COMM_WORLD, &np);
163 n = atoi(
getCmdOption(input_str, input_str+in_num,
"-n"));
167 if (
getCmdOption(input_str, input_str+in_num,
"-sp_frac")){
168 sp_frac = atof(
getCmdOption(input_str, input_str+in_num,
"-sp_frac"));
169 if (sp_frac < 0) sp_frac = .1;
173 World dw(argc, argv);
176 printf(
"Running 2-MIS with n=%d, sp_frac=%lf\n",n,sp_frac);
181 printf(
"2-MIS passed.\n");
183 printf(
"2-MIS FAILED.\n");
dtype d
tensor value associated with index
bool test_mis2(int n, double sp_frac)
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
dtype get_val()
returns scalar value
Semiring is a Monoid with an addition multiplicaton function addition must have an identity and be as...
Vector class which encapsulates a 1D tensor.
an instance of the CTF library (world) on a MPI communicator
int64_t k
key, global index [i1,i2,...] specified as i1+len[0]*i2+...
int main(int argc, char **argv)
index-value pair used for tensor data input
CTF::World * wrld
distributed processor context on which tensor is defined
Scalar class which encapsulates a 0D tensor.
int rank
rank of local processor
Vector< float > mis2(Matrix< float > &undir_A)
void sparsify()
reduce tensor to sparse format, storing only nonzero data, or data above a specified threshold...
int64_t nnz_tot
maximum number of local nonzero elements over all procs
void fill_sp_random(dtype rmin, dtype rmax, double frac_sp)
generate roughly frac_sp*dense_tensor_size nonzeros between rmin and rmax, works only for dtype in {f...
an instance of a tensor within a CTF world
char * getCmdOption(char **begin, char **end, const std::string &option)
void write(int64_t npair, int64_t const *global_idx, dtype const *data)
writes in values associated with any set of indices The sparse data is defined in coordinate format...