Exemplo n.º 1
0
//-----------------------------------------------------------------------------
TEST(conduit_blueprint_mcarray_examples, mcarray_xyz)
{
    // we are using one node to hold group of example mcarrays purely out of 
    // convenience
    Node dsets;
    index_t npts = 100;
    
    blueprint::mcarray::examples::xyz("interleaved",
                                  npts,
                                  dsets["interleaved"]);

    blueprint::mcarray::examples::xyz("separate",
                                  npts,
                                  dsets["separate"]);

    blueprint::mcarray::examples::xyz("contiguous",
                                  npts,
                                  dsets["contiguous"]);
    NodeIterator itr = dsets.children();
    
    while(itr.has_next())
    {
        Node info;
        Node &mcarray = itr.next();
        std::string name = itr.name();
        // TODO: tests!
    }
}
Exemplo n.º 2
0
//------------------------------------------------------------------------------
void TreeDrawer::CalcCoordinates ()
{
	double l = t->GetNumLeaves();
    leafGap = height / (l - 1.0);
	if (rooted)
    	nodeGap = width / l;
    else
    	nodeGap = width / (l - 1.0);
	leafCount = 0;

    if (rooted)
    {
    	// Allow for edge below root
    	left += nodeGap;
        width -= nodeGap;
    }

    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	CalcLeaf (q);
        }
        else
        {
			CalcInternal (q);
        }

        q = n.next();
    }

}
Exemplo n.º 3
0
//------------------------------------------------------------------------------
void RectangleTreeDrawer::CalcCoordinates ()
{
	t->MakeNodeList();
    maxDepth = 0;
    // Clear internal node depths
    for (int i = t->GetNumLeaves(); i < t->GetNumNodes(); i++)
    {
    	(*t)[i]->SetDepth(0);
    }
    for (int i = 0; i < t->GetNumLeaves();  i++)
    {
    	NodePtr p = (*t)[i]->GetAnc();
        int count = 1;
        while (p)
        {
        	if (count > p->GetDepth())
            {
            	p->SetDepth(count);
                if (count > maxDepth)
                	maxDepth = count;
            }
            count++;
            p = p->GetAnc();
        }
    }

 	double l = t->GetNumLeaves();
    leafGap = height / (l - 1.0);
	l = maxDepth + 1.0;
	if (rooted)
    	nodeGap = width / l;
    else
    	nodeGap = width / (l - 1.0);
	leafCount = 0;

    if (rooted)
    {
    	// Allow for edge below root
    	left += nodeGap;
        width -= nodeGap;
    }

    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	CalcLeaf (q);
        }
        else
        {
			CalcInternal (q);
        }

        q = n.next();
    }

}
Exemplo n.º 4
0
//------------------------------------------------------------------------------
void TreeOrder::Order ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (!q->IsLeaf ())
			SortDescendants (q);

        q = n.next();
    }
}
Exemplo n.º 5
0
//------------------------------------------------------------------------------
void AlphaOrder::Order ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        	labels[q] = q->GetLabel();
        q = n.next();
    }
	q = n.begin();
    while (q)
    while (q)
    {
    	if (!q->IsLeaf ())
        {
			SortDescendants (q);
            labels[q] = labels[q->GetChild()];
        }

        q = n.next();
    }
}
Exemplo n.º 6
0
//------------------------------------------------------------------------------
void TreeDrawer::Draw ()
{
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	DrawLeaf (q);
        }
        else
        {
			DrawInternal (q);
        }

        q = n.next();
    }
    if (rooted)
    {
    	DrawRoot ();
    }
}
Exemplo n.º 7
0
//------------------------------------------------------------------------------
TreeDrawer::TreeDrawer (Tree *tree)
{
	t = tree;
    rooted = true;
    showInternalLabels = true;
    showLeafLabels = true;
    left = 0.0;
    top = 0.0;
    width = 400.0;
    height = 400.0;
    leafCount = 0;
    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	point p;
        	node_coordinates[q] = p;
        }
        q = n.next();
    }
}
Exemplo n.º 8
0
//---------------------------------------------------------------------------//
int
all_gatherv(Node &send_node,
            Node &recv_node,
            MPI_Comm mpi_comm)
{
    Node n_snd_compact;
    send_node.compact_to(n_snd_compact);

    int m_size = mpi::size(mpi_comm);

    std::string schema_str = n_snd_compact.schema().to_json();

    int schema_len = schema_str.length() + 1;
    int data_len   = n_snd_compact.total_bytes();

    // to do the conduit gatherv, first need a gather to get the
    // schema and data buffer sizes

    int snd_sizes[] = {schema_len, data_len};

    Node n_rcv_sizes;

    Schema s;
    s["schema_len"].set(DataType::c_int());
    s["data_len"].set(DataType::c_int());
    n_rcv_sizes.list_of(s,m_size);

    int mpi_error = MPI_Allgather( snd_sizes, // local data
                                   2, // two ints per rank
                                   MPI_INT, // send ints
                                   n_rcv_sizes.data_ptr(),  // rcv buffer
                                   2,  // two ints per rank
                                   MPI_INT,  // rcv ints
                                   mpi_comm); // mpi com

    CONDUIT_CHECK_MPI_ERROR(mpi_error);

    Node n_rcv_tmp;

    int  *schema_rcv_counts = NULL;
    int  *schema_rcv_displs = NULL;
    char *schema_rcv_buff   = NULL;

    int  *data_rcv_counts = NULL;
    int  *data_rcv_displs = NULL;
    char *data_rcv_buff   = NULL;


    // alloc data for the mpi gather counts and displ arrays
    n_rcv_tmp["schemas/counts"].set(DataType::c_int(m_size));
    n_rcv_tmp["schemas/displs"].set(DataType::c_int(m_size));

    n_rcv_tmp["data/counts"].set(DataType::c_int(m_size));
    n_rcv_tmp["data/displs"].set(DataType::c_int(m_size));

    // get pointers to counts and displs
    schema_rcv_counts = n_rcv_tmp["schemas/counts"].value();
    schema_rcv_displs = n_rcv_tmp["schemas/displs"].value();

    data_rcv_counts = n_rcv_tmp["data/counts"].value();
    data_rcv_displs = n_rcv_tmp["data/displs"].value();

    int schema_curr_displ = 0;
    int data_curr_displ   = 0;
    int i=0;

    NodeIterator itr = n_rcv_sizes.children();
    while(itr.has_next())
    {
        Node &curr = itr.next();

        int schema_curr_count = curr["schema_len"].value();
        int data_curr_count   = curr["data_len"].value();

        schema_rcv_counts[i] = schema_curr_count;
        schema_rcv_displs[i] = schema_curr_displ;
        schema_curr_displ   += schema_curr_count;

        data_rcv_counts[i] = data_curr_count;
        data_rcv_displs[i] = data_curr_displ;
        data_curr_displ   += data_curr_count;

        i++;
    }

    n_rcv_tmp["schemas/data"].set(DataType::c_char(schema_curr_displ));
    schema_rcv_buff = n_rcv_tmp["schemas/data"].value();

    mpi_error = MPI_Allgatherv( const_cast <char*>(schema_str.c_str()),
                                schema_len,
                                MPI_CHAR,
                                schema_rcv_buff,
                                schema_rcv_counts,
                                schema_rcv_displs,
                                MPI_CHAR,
                                mpi_comm);

    CONDUIT_CHECK_MPI_ERROR(mpi_error);

    // build all schemas from JSON, compact them.
    Schema rcv_schema;
    //TODO: should we make it easer to create a compact schema?
    Schema s_tmp;
    for(int i=0; i < m_size; i++)
    {
        Schema &s = s_tmp.append();
        s.set(&schema_rcv_buff[schema_rcv_displs[i]]);
    }

    s_tmp.compact_to(rcv_schema);



    // allocate data to hold the gather result
    recv_node.set(rcv_schema);
    data_rcv_buff = (char*)recv_node.data_ptr();

    mpi_error = MPI_Allgatherv( n_snd_compact.data_ptr(),
                                data_len,
                                MPI_CHAR,
                                data_rcv_buff,
                                data_rcv_counts,
                                data_rcv_displs,
                                MPI_CHAR,
                                mpi_comm);

    CONDUIT_CHECK_MPI_ERROR(mpi_error);

    return mpi_error;
}
Exemplo n.º 9
0
//------------------------------------------------------------------------------
void CircleTreeDrawer::CalcCoordinates ()
{
	t->MakeNodeList();
    maxDepth = 0;
    // Clear internal node depths
    for (int i = t->GetNumLeaves(); i < t->GetNumNodes(); i++)
    {
    	(*t)[i]->SetDepth(0);
    }
    for (int i = 0; i < t->GetNumLeaves();  i++)
    {
    	NodePtr p = (*t)[i]->GetAnc();
        int count = 1;
        while (p)
        {
        	if (count > p->GetDepth())
            {
            	p->SetDepth(count);
                if (count > maxDepth)
                	maxDepth = count;
            }
            count++;
            p = p->GetAnc();
        }
    }

	leaf_angle = 2 * M_PI / t->GetNumLeaves();
    left = top = 0.0;
    width = height = 400.0;
    leaf_radius = width / 2.0;
    leafCount = 0;
    nodeGap = leaf_radius / double(maxDepth);
    origin.x = 0.0;
    origin.y = 0.0;

    NodeIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	CalcLeaf (q);
        }
        else
        {
			CalcInternal (q);
        }

        q = n.next();
    }

    // Translate
    origin.x = left + (width/2.0);
    origin.y = top + (height/2.0);
    q = n.begin();
    while (q)
    {
    	node_coordinates[q].x += origin.x;
        node_coordinates[q].y += origin.y;
    	node_backarc[q].x += origin.x;
        node_backarc[q].y += origin.y;
        q = n.next();
    }


}
Exemplo n.º 10
0
//------------------------------------------------------------------------------
void PhylogramDrawer::CalcCoordinates ()
{
	// 1. Get path lengths
	mMaxPathLength = 0.0;
	t->GetRoot()->SetPathLength (t->GetRoot()->GetEdgeLength()); // modify for rooted?


    // duh! this needs to be preorder!!!!!!!!!

    PreorderIterator <Node> n (t->GetRoot());
    Node *q = n.begin();
    while (q)
    {
       	double d = q->GetEdgeLength();
        if (d < 0.00001)
        	d = 0.0;
        if (q != t->GetRoot())
	    	q->SetPathLength (q->GetAnc()->GetPathLength() + d);
		if (q->GetPathLength() > mMaxPathLength)
			mMaxPathLength = q->GetPathLength();
        q = n.next();
    }

    // Is the tree ultrametric? (should really be a method of the tree class...)
    mUltrametric = true;
    NodeIterator <Node> u (t->GetRoot());
    q = u.begin();
    while (q && mUltrametric)
    {
        if (q->IsLeaf())
        {
            double d = q->GetPathLength() - mMaxPathLength;
            mUltrametric = (fabs(d) <= 0.0001); //remove std:: in front of fabs to comply with GCC 4.0 (added by BCO)
//            cout << mMaxPathLength << ":" << q->GetPathLength() << " " << d << endl;
        }
        q = u.next();
    }
            

    // Allow for scale bar

#if USE_VC2
	scalebar_space = Port.GetFontHeight() * 2;
#endif		

#if USE_WXWINDOWS
	scalebar_space = dc->GetCharHeight() * 2;
#endif		


#if USE_PS
	scalebar_space = font.GetSize() * 2;
#endif

	height -= scalebar_space;

 	double l = t->GetNumLeaves();
    leafGap = height / (l - 1.0);
	leafCount = 0;

    NodeIterator <Node> po (t->GetRoot());
    q = po.begin();
    while (q)
    {
    	if (q->IsLeaf ())
        {
        	CalcLeaf (q);
        }
        else
        {
			CalcInternal (q);
        }

        q = po.next();
    }

}