Ejemplo n.º 1
0
    GraphHelper_Scotch(const CrsMatrixType& A,
                       const int seed = GraphHelper::DefaultRandomSeed) {

        _label = "GraphHelper_Scotch::" + A.Label();

        _is_ordered = false;
        _cblk  = 0;

        // scotch does not allow self-contribution (diagonal term in sparse matrix)
        _base  = 0; //A.BaseVal();
        _m     = A.NumRows();
        _nnz   = A.NumNonZeros();

        _rptr  = size_type_array(_label+"::RowPtrArray", _m+1);
        _cidx  = ordinal_type_array(_label+"::ColIndexArray", _nnz);

        _perm  = ordinal_type_array(_label+"::PermutationArray", _m);
        _peri  = ordinal_type_array(_label+"::InvPermutationArray", _m);
        _range = ordinal_type_array(_label+"::RangeArray", _m);
        _tree  = ordinal_type_array(_label+"::TreeArray", _m);

        // create a graph structure without diagonals
        A.convertGraph(_nnz, _rptr, _cidx);

        int ierr = 0;
        ordinal_type *rptr = reinterpret_cast<ordinal_type*>(_rptr.ptr_on_device());
        ordinal_type *cidx = reinterpret_cast<ordinal_type*>(_cidx.ptr_on_device());

        if (seed != GraphHelper::DefaultRandomSeed) {
            SCOTCH_randomSeed(seed);
            SCOTCH_randomReset();
        }

        ierr = SCOTCH_graphInit(&_graph);
        CHKERR(ierr);
        ierr = SCOTCH_graphBuild(&_graph,             // scotch graph
                                 _base,               // base value
                                 _m,                  // # of vertices
                                 rptr,                // column index array pointer begin
                                 rptr+1,              // column index array pointer end
                                 NULL,                // weights on vertices (optional)
                                 NULL,                // label array on vertices (optional)
                                 _nnz,                // # of nonzeros
                                 cidx,                // column index array
                                 NULL);
        CHKERR(ierr);  // edge load array (optional)
        ierr = SCOTCH_graphCheck(&_graph);
        CHKERR(ierr);
    }