コード例 #1
0
ファイル: test-cblq-dense.cpp プロジェクト: daboyuka/PIQUE
int main(int argc, char **argv) {
    CBLQRegionEncoder<2> builder(CBLQRegionEncoderConfig(true), 64);

    builder.push_bits(3, true);
    builder.push_bits(4, false);
    builder.push_bits(2, true);
    builder.push_bits(7, false);

    builder.push_bits(24, true);
    builder.push_bits(7, false);
    builder.push_bits(1, true);

    // Try consecutive 1-pushes
    builder.push_bits(16, true);
    builder.finalize();

    boost::shared_ptr< CBLQRegionEncoding<2> > region = builder.to_region_encoding();

    region->dump();
    printf("\n\n");
    // Expected:
    // Level 0: 2121
    // Level 1: 2220 1102
    // Level 2:
    // Dense suffix: 1110 0001 1000 0001

    CBLQRegionEncoder<2> builder2(CBLQRegionEncoderConfig(true), 64);

    builder2.push_bits(7, true);
    builder2.push_bits(2, false);
    builder2.push_bits(7, true);

    builder2.push_bits(16, false);

    builder2.push_bits(32, false);
    builder2.finalize();

    boost::shared_ptr< CBLQRegionEncoding<2> > region2 = builder2.to_region_encoding();

    region2->dump();
    printf("\n\n");
    // Expected:
    // Level 0: 2000
    // Level 1: 1221
    // Level 2:
    // Dense suffix: 1110 0111

    CBLQSetOperations<2> setops(CBLQSetOperationsConfig(false));
    boost::shared_ptr< CBLQRegionEncoding<2> > uregion = setops.binary_set_op(region, region2, NArySetOperation::UNION);

    uregion->dump();
    printf("\n\n");
    // Expected:
    // Level 0: 2121
    // Level 1: 1221 1102
    // Level 2:
    // Dense suffix: 1111 1111 0001

    uregion->compact();
    uregion->dump();
    printf("\n\n");
    // Expected:
    // Level 0: 1121
    // Level 1: 1102
    // Level 2:
    // Dense suffix: 0001

    boost::shared_ptr< CBLQRegionEncoding<2> > uregion2 = setops.binary_set_op(uregion, uregion, NArySetOperation::UNION);

    uregion2->dump();
    printf("\n\n");
    // Expected:
    // Level 0: 1121
    // Level 1: 1102
    // Level 2:
    // Dense suffix: 0001

    boost::shared_ptr< CBLQRegionEncoding<2> > uregion3 = setops.binary_set_op(uregion, region, NArySetOperation::UNION);

    uregion3->dump();
    printf("\n\n");
    // Expected:
    // Level 0: 1121
    // Level 1: 1102
    // Level 2:
    // Dense suffix: 0001
}
コード例 #2
0
ファイル: matrix-conv.hpp プロジェクト: anurags92/sketchmap
template <class T> PCrsMatrix<U>::PCrsMatrix(const CrsMatrix<T>& s, const  MPI_Comm ncomm)
{
    mpi_init(ncomm);
    
    int iamsender=(s.rows()>0?1:0);    //! we rely on the fact that only one node has this cond. fulfilled.

    // now we let everyone know who is the sender
    std::valarray<int> slist(mysize);
    MPI_Allgather(&iamsender, 1, MPI_INTEGER, &slist[0], 1, MPI_INTEGER, mycomm);
    int sender=-1;
    
    for (int i=0; i< mysize; ++i) 
        if (slist[i]==1) if(sender==-1) sender=i; else ERROR("More than one process qualified as sender!");
    if (sender==-1) ERROR("No process qualified as sender!");
    
    // now we get the matrix size and resize it.
    typename PCrsMatrix<U>::index_type dim[2];
    if (iamsender) { dim[0]=s.rows(); dim[1]=s.cols(); }
    MPI_Bcast(dim,2,mpi_index,sender,mycomm);
    resize(dim[0],dim[1]);
    
    // now we copy the options, as if it were an array of char...
    MPI_Bcast(&(const_cast<CrsMatrix<T> &>(s).pops),sizeof(pops),MPI_CHAR,sender,mycomm);
    setops(s.pops);
    
    // now we can send out the row indices to the nodes.
    unsigned long nmyrows=nroots[myrank+1]-nroots[myrank];
    MPI_Request rreq;
    MPI_Irecv(&pmat.rpoints[0],nmyrows+1,mpi_index,sender,101,mycomm,&rreq);
    
    if (iamsender) {
        for (int i=0; i<mysize; ++i)
            MPI_Send(&(const_cast<CrsMatrix<T> &>(s).rpoints[nroots[i]]),nroots[i+1]-nroots[i]+1,mpi_index,i,101,mycomm);
    };
    
    //wait for receive
    MPI_Status rstatus;
    MPI_Wait(&rreq, &rstatus);
    //then shift the indices as necessary, since we are getting chunks of data
    for (typename PCrsMatrix<U>::index_type i=1;i<=nmyrows; ++i)
        pmat.rpoints[i]-=pmat.rpoints[0];
    pmat.rpoints[0]=0;
    pmat.presize(pmat.rpoints[nmyrows]);
    
    //very well. now we can share the column indices and the data!
    MPI_Request rreq_i, rreq_d;
    MPI_Irecv(&pmat.indices[0],pmat.rpoints[nmyrows],mpi_index,sender,202,mycomm,&rreq_i);
    
    if (iamsender) {
        for (int i=0; i<mysize; ++i)
            MPI_Send(&(const_cast<CrsMatrix<T> &>(s).indices[s.rpoints[nroots[i]]]),
                     s.rpoints[nroots[i+1]]-s.rpoints[nroots[i]],mpi_index,i,202,mycomm);
    };
    
    MPI_Irecv(&pmat.values[0],pmat.rpoints[nmyrows],mpi_data,sender,303,mycomm,&rreq_d);
    
    if (iamsender) {
        for (int i=0; i<mysize; ++i)
            MPI_Send(&(const_cast<CrsMatrix<T> &>(s).values[s.rpoints[nroots[i]]]),
                     s.rpoints[nroots[i+1]]-s.rpoints[nroots[i]],mpi_data,i,303,mycomm);
    };
    MPI_Wait(&rreq_i, &rstatus);
    MPI_Wait(&rreq_d, &rstatus);
}