示例#1
0
int main(int argc, char* argv[])
{
    int rank,size,offset;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
  
    ostringstream convert;
    convert << rank+1;
    string file = "data"+ convert.str();
    int numLocal, totalNode;
    Graph g(rank,file);

    Matpair buf(4);
    Vec F;
    numLocal = g.localNode();
    offset = rank*numLocal;
    int root = 512;
    int finish,localfinish;
    int parents[numLocal];
    for (int i=0;i<numLocal;i++){
        parents[i] = -1;
    }
    if (rank == root/numLocal){
        F.push_back(root);
        parents[root-offset] = -2;}
    localfinish = !F.empty(); 

    Vec nxFr;
   
    int dep=0;
    int depth[numLocal];
    for (int i = 0; i < numLocal; i++){
	    depth[i]=0;
    }

    while(1){
    	localfinish=!F.empty();
	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Allreduce(&localfinish,&finish,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD);
    	if (finish==0)
		break;
        if (!F.empty()){
	   for (Vec::iterator i = F.begin();i != F.end(); i++){
		depth[*i-offset] = dep+1;
		cout << "node "<< *i <<" depth: "<<dep+1<<endl;
	   }
	}

        nextFrBuf(g,F,rank,size,buf,offset);
        alltoallPersonalized(buf,parents,nxFr,size,offset);
	F=nxFr;
	dep++;
    } 

    MPI_Finalize();
    return 0;
}
示例#2
0
void Instruction::update_in_a_cycle() {
    ++Instruction::cur_op_id;
    Vec<std::pair<Instruction *,unsigned>> stack;
    stack.emplace_back( this, 0 );
    while ( true ) {
        std::pair<Instruction *,unsigned> t = stack.back();

        // instruction
        if ( t.first->op_id == Instruction::cur_op_id ) {
            stack.pop_back();
            if ( t.first->num_in_dfs_stack >= 0 )
                for( unsigned j = t.first->num_in_dfs_stack; j < stack.size(); ++j )
                    stack[ j ].first->in_a_cycle = true;
        } else {
            t.first->op_id = Instruction::cur_op_id;
            t.first->num_in_dfs_stack = stack.size() - 1;
        }

        // next
        while ( stack.back().second >= stack.back().first->next.size() ) {
            stack.back().first->num_in_dfs_stack = - 1;
            stack.pop_back();
            if ( stack.empty() )
                return;
        }
        stack.emplace_back( stack.back().first->next[ stack.back().second++ ].inst, 0 );
    }
}
示例#3
0
文件: ascendvec.cpp 项目: herumi/misc
 uint32_t get(uint32_t pos) const
 {
     assert(!v_.empty() && v_[0] == 0);
     Vec::const_iterator i = std::lower_bound(v_.begin(), v_.end(), pos + 1);
     if (i == v_.end()) return (uint32_t)v_.size() - 1;
     return (uint32_t)std::distance(v_.begin(), i) - 1;
 }
示例#4
0
TEST(VectorMapTest, EmptyTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_TRUE(v.end() == v.find(10));
}
示例#5
0
// median of the nonzero elements of `s.homework', or `0' if no such elements exist
double optimistic_median(const Student_info& s)
{
    Vec<double> nonzero;
    remove_copy(s.homework.begin(), s.homework.end(),
                back_inserter(nonzero), 0);

    if (nonzero.empty())
        return grade(s.midterm, s.final, 0);
    else
        return grade(s.midterm, s.final, median(nonzero));
示例#6
0
TEST(VectorMapTest, InsertTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	v.insert(10, 1);
	ASSERT_TRUE(v.end() != v.find(10));
	Pair const& p = *(v.find(10));
	ASSERT_EQ(1, p.second);
}
示例#7
0
文件: arrayMap.cpp 项目: nodakai/exp
    void repack() {
        // dump();

        const int oWidth = (m_vec.size() - 1 - 1) / 2, nWidth = 2 * oWidth; // half widths
        Vec v(2 * nWidth + 1 + 1);
        copy(m_vec.begin() + 1, m_vec.end(), v.begin() + oWidth + 1);
        if ( ! m_vec.empty())
            v[0] = m_vec[0];
        swap(m_vec, v);
        m_minKey -= oWidth; m_maxKey += oWidth;
    }
示例#8
0
 T pop() {
     if (front->empty()) {
         js::Reverse(back->begin(), back->end());
         Vec *tmp = front;
         front = back;
         back = tmp;
     }
     T item = front->back();
     front->popBack();
     return item;
 }        
示例#9
0
TEST(VectorMapTest, UpdateTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_FALSE( v.update(10, 1) );
	ASSERT_TRUE( v.update(10, 1) );
	Pair const& p = *(v.find(10));
	ASSERT_EQ(1, p.second);
	ASSERT_TRUE( v.update(10, 2) );
	Pair const& p2 = *(v.find(10));
	ASSERT_EQ(2, p2.second);
	ASSERT_EQ(1, v.size());
}
示例#10
0
void nextFrBuf(const Graph &g, Vec Fr, int rank, int size,  Matpair &buf, int offset )
{
    if (Fr.empty())
        return;
    int r, frNode;
    buf.clear();
    Vec::iterator i,j;
    for(i = Fr.begin(); i != Fr.end(); i++){
        frNode = *i - offset;
        for (j = g.adj[frNode].begin(); j != g.adj[frNode].end(); j++){
            r = *j/g.localNode();
            
            buf[r].push_back(make_pair(*i,*j));
        }
    }
}
示例#11
0
TEST(VectorMapTest, EraseTest)
{
	Vec v;
	ASSERT_TRUE(v.empty());
	ASSERT_EQ(0, v.size());
	ASSERT_FALSE(v.remove(10));
	v.insert(10, 1);
	v.insert(11, 2);
	ASSERT_TRUE(v.end() != v.find(10));
	{
		Pair const& p = *(v.find(10));
		ASSERT_EQ(1, p.second);
	}
	{
		Pair const& p = *(v.erase( v.find(10) ));
		ASSERT_EQ(2, p.second);
	}
}
示例#12
0
 bool empty() { return front->empty() && back->empty(); }
示例#13
0
 bool empty() { return vec.empty(); }
示例#14
0
文件: ascendvec.cpp 项目: herumi/misc
 void append(uint32_t pos)
 {
     assert(v_.empty() ? pos == 0 : v_.back() < pos);
     v_.push_back(pos);
 }