File: InducedSubgraphsTest.cpp

package info (click to toggle)
combblas 2.0.0-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 190,476 kB
  • sloc: cpp: 55,912; ansic: 25,134; sh: 3,691; makefile: 548; csh: 66; python: 49; perl: 21
file content (49 lines) | stat: -rw-r--r-- 1,676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <mpi.h>
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <sstream>
#include "CombBLAS/CombBLAS.h"

int main(int argc, char *argv[])
{
    int nprocs, myrank;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank);

    if (argc < 3) {
        if (!myrank)
            std::cerr << "Usage: ./Subgraphs2ProcsTest <MatrixA> <VectorAssignments>" << std::endl;
        MPI_Finalize();
        return -1;
    }
    {
        if (!myrank) std::cerr << "processor grid: (" << std::sqrt(nprocs) << " x " << std::sqrt(nprocs) << ")" << std::endl;

        std::shared_ptr<combblas::CommGrid> fullWorld;
        fullWorld.reset(new combblas::CommGrid(MPI_COMM_WORLD, 0, 0));

        combblas::SpParMat<int, double, combblas::SpCCols<int, double> > A(fullWorld);
        combblas::FullyDistVec<int, int> assignments(A.getcommgrid());

        A.ParallelReadMM(std::string(argv[1]), true, combblas::maximum<double>());
        assignments.ParallelRead(std::string(argv[2]), true, combblas::maximum<int>());

        std::vector<int> local_idx_map;

        combblas::SpCCols<int, double> locmat = A.InducedSubgraphs2Procs(assignments, local_idx_map);

        for (auto colit = locmat.begcol(); colit != locmat.endcol(); ++colit) {
            for (auto nzit = locmat.begnz(colit); nzit != locmat.endnz(colit); ++nzit) {
                std::cout << myrank << ": " << local_idx_map[nzit.rowid()]+1 << "\t" << local_idx_map[colit.colid()]+1 << "\t" << nzit.value() << std::endl;
            }
        }
        std::cout << std::endl;

    }

    MPI_Finalize();
    return 0;
}