Exemplo n.º 1
0
int write_insert_to_trace(bptree_session *bps, bptree_node *x,
		bptree_key_val *kv, int pos, int lvl)
{
	int i;
	unsigned char *kk, *vv;
	int16_t bpt_id;
	size_t nsize;
	char uu[40],res[20];
	char nodestr[4096];
	get_trace_file();

	bptree_key_value_to_string_kv(bps, kv, nodestr);
	prepend_client_and_whitespace(bps, lvl);
	fprintf(trace_fp, "Insert key: %s pos %d lvl %d\n", nodestr, pos, lvl);
	bzero(nodestr, 4096);

	// X
	prepend_client_and_whitespace(bps, lvl);
	write_node_info(bps, nodestr, x);
	fprintf(trace_fp, "X  : %s\n", nodestr);

	bzero(nodestr, 4096);

	return 0;
}
void data_update(HashTable* HT_Elem_Ptr, HashTable* HT_Node_Ptr, Recv* RecvHead, int myid, int numprocs, int h_count)
{
    int i, j, k;
    
    Recv* recv;
    Recv* recv_new;
    
    Element* EmTemp;
    Element* SonTemp1;
    Element* SonTemp2;
    
    unsigned* keyP;
    unsigned* sonP;
    
    void* p;
    
    /*--scan the Recv list--*/
    recv = RecvHead->next;
    while (recv)
    {
        EmTemp = recv->targetP;
        if(recv->sender_gen == EmTemp->get_gen())
        {
            assert(recv->side < 4);
            if(EmTemp->get_refined_flag()) //-- if the receptor was refined
            {
                /*-- case 1:(refer to my note book to know the definition of each case)
                 sender and receptor were both refined and they are on the same generation-----*/
                /*-- case 3:
                 sender was not refined but receptor was and they are on the same generation---*/

                sonP = EmTemp->getson();
                
                switch (recv->side)
                {
                    
                    case 0: //-- filling the neigbor info for son 0 and 1
                    
                        SonTemp1 = (Element*) HT_Elem_Ptr->lookup(sonP); //--son 0, side 0
                        SonTemp2 = (Element*) HT_Elem_Ptr->lookup(sonP + KEYLENGTH); //--son 1, side 0
                                
                        if(recv->sender_refined) //--sender was refined, case 1
                        {
                            
                            SonTemp1->putneighbor(recv->sender_son2, 0);
                            if(recv->sender_order[1] > *SonTemp1->get_order())
                                SonTemp1->put_order(0, recv->sender_order[1]);
                            SonTemp1->put_neigh_proc(0, recv->sender_id);
                            SonTemp1->put_neigh_gen(0, recv->sender_gen + 1); //--999
                                    
                            SonTemp2->putneighbor(recv->sender_son1, 0);
                            if(recv->sender_order[0] > *SonTemp2->get_order())
                                SonTemp2->put_order(0, recv->sender_order[0]);
                            SonTemp2->put_neigh_proc(0, recv->sender_id);
                            SonTemp2->put_neigh_gen(0, recv->sender_gen + 1); //--999
                                    
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 0, 1);
                            
                        }
                        else //--sender was not refined, case 3
                        {
                            
                            SonTemp1->putneighbor(EmTemp->get_neighbors(), 0);
                            SonTemp1->put_neigh_proc(0, recv->sender_id);
                            SonTemp1->put_neigh_gen(0, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *SonTemp1->get_order())
                                SonTemp1->put_order(0, recv->sender_order[0]);
                            
                            SonTemp2->put_neigh_proc(0, recv->sender_id);
                            SonTemp2->putneighbor(recv->sender, 0);
                            SonTemp2->put_neigh_gen(0, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *SonTemp2->get_order())
                                SonTemp2->put_order(0, recv->sender_order[0]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 0, 3);
                            
                        }
                        break;
                        
                    case 1: //-- son 1 and 2
                    
                        SonTemp1 = (Element*) HT_Elem_Ptr->lookup(sonP + KEYLENGTH); //--son 1, side 1
                        SonTemp2 = (Element*) HT_Elem_Ptr->lookup(sonP + 2 * KEYLENGTH); //--son 2, side 1
                                
                        if(recv->sender_refined)
                        {
                            
                            SonTemp1->putneighbor(recv->sender_son2, 1);
                            SonTemp1->put_neigh_proc(1, recv->sender_id);
                            SonTemp1->put_neigh_gen(1, recv->sender_gen + 1); //--999
                            if(recv->sender_order[1] > *(SonTemp1->get_order() + 1))
                                SonTemp1->put_order(1, recv->sender_order[1]);
                            
                            SonTemp2->putneighbor(recv->sender_son1, 1);
                            SonTemp2->put_neigh_proc(1, recv->sender_id);
                            SonTemp2->put_neigh_gen(1, recv->sender_gen + 1); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 1))
                                SonTemp2->put_order(1, recv->sender_order[0]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 1, 1);
                            
                        }
                        else
                        {
                            
                            SonTemp1->putneighbor(recv->sender, 1);
                            SonTemp1->put_neigh_proc(1, recv->sender_id);
                            SonTemp1->put_neigh_gen(1, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 1))
                                SonTemp1->put_order(1, recv->sender_order[0]);
                            
                            SonTemp2->putneighbor(recv->sender, 1);
                            SonTemp2->put_neigh_proc(1, recv->sender_id);
                            SonTemp2->put_neigh_gen(1, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 1))
                                SonTemp1->put_order(1, recv->sender_order[0]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 1, 3);
                            
                        }
                        break;
                        
                    case 2: //-- son 2 and 3
                    
                        SonTemp1 = (Element*) HT_Elem_Ptr->lookup(sonP + 2 * KEYLENGTH); //--son 2, side 2
                        SonTemp2 = (Element*) HT_Elem_Ptr->lookup(sonP + 3 * KEYLENGTH); //--son 3, side 2
                                
                        if(recv->sender_refined)
                        {
                            
                            SonTemp1->putneighbor(recv->sender_son2, 2);
                            SonTemp1->put_neigh_proc(2, recv->sender_id);
                            SonTemp1->put_neigh_gen(2, recv->sender_gen + 1); //--999
                            if(recv->sender_order[1] > *(SonTemp1->get_order() + 2))
                                SonTemp1->put_order(2, recv->sender_order[1]);
                            
                            SonTemp2->putneighbor(recv->sender_son1, 2);
                            SonTemp2->put_neigh_proc(2, recv->sender_id);
                            SonTemp2->put_neigh_gen(2, recv->sender_gen + 1); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 2))
                                SonTemp2->put_order(2, recv->sender_order[1]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 2, 1);
                            
                        }
                        else
                        {
                            
                            SonTemp1->putneighbor(recv->sender, 2);
                            SonTemp1->put_neigh_proc(2, recv->sender_id);
                            SonTemp1->put_neigh_gen(2, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 2))
                                SonTemp1->put_order(2, recv->sender_order[0]);
                            
                            SonTemp2->putneighbor(recv->sender, 2);
                            SonTemp2->put_neigh_proc(2, recv->sender_id);
                            SonTemp2->put_neigh_gen(2, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 2))
                                SonTemp1->put_order(2, recv->sender_order[0]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 2, 3);
                            
                        }
                        break;
                        
                    case 3: //-- son 3 and 0
                    
                        SonTemp1 = (Element*) HT_Elem_Ptr->lookup(sonP + 3 * KEYLENGTH); //--son 3, side 3
                        SonTemp2 = (Element*) HT_Elem_Ptr->lookup(sonP); //--son 0, side 3
                                
                        if(recv->sender_refined)
                        {
                            
                            SonTemp1->putneighbor(recv->sender_son2, 3);
                            SonTemp1->put_neigh_proc(3, recv->sender_id);
                            SonTemp1->put_neigh_gen(3, recv->sender_gen + 1); //--999
                            if(recv->sender_order[1] > *(SonTemp1->get_order() + 3))
                                SonTemp1->put_order(3, recv->sender_order[1]);
                            
                            SonTemp2->putneighbor(recv->sender_son1, 3);
                            SonTemp2->put_neigh_proc(3, recv->sender_id);
                            SonTemp2->put_neigh_gen(3, recv->sender_gen + 1); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 3))
                                SonTemp2->put_order(3, recv->sender_order[1]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 3, 1);
                            
                        }
                        else
                        {
                            
                            SonTemp1->putneighbor(recv->sender, 3);
                            SonTemp1->put_neigh_proc(3, recv->sender_id);
                            SonTemp1->put_neigh_gen(3, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 3))
                                SonTemp1->put_order(3, recv->sender_order[0]);
                            
                            SonTemp2->putneighbor(recv->sender, 3);
                            SonTemp2->put_neigh_proc(3, recv->sender_id);
                            SonTemp2->put_neigh_gen(3, recv->sender_gen); //--999
                            if(recv->sender_order[0] > *(SonTemp2->get_order() + 3))
                                SonTemp1->put_order(3, recv->sender_order[0]);
                            
                            write_node_info(HT_Node_Ptr, SonTemp1, SonTemp2, 3, 3);
                            
                        }
                        break;
                        
                }
                
            }
            else
            {
                
                /*--case 2:
                 sender was refined but receptor was not and they are on the same generation--*/

                if(recv->sender_refined)
                {
                    
                    switch (recv->side % 4)
                    //--refer to the definition to understand the following
                    {
                        
                        case 0:

                            EmTemp->put_neigh_proc(0, recv->sender_id);
                            EmTemp->put_neigh_proc(4, recv->sender_id);
                            EmTemp->putneighbor(recv->sender_son2, 0);
                            EmTemp->putneighbor(recv->sender_son1, 4);
                            EmTemp->put_neigh_gen(0, recv->sender_gen + 1); //--999
                            EmTemp->put_neigh_gen(4, recv->sender_gen + 1); //--999
                                    
                            if(recv->sender_order[0] > *EmTemp->get_order())
                                EmTemp->put_order(0, recv->sender_order[0]);
                            if(recv->sender_order[1] > *EmTemp->get_order())
                                EmTemp->put_order(0, recv->sender_order[1]);
                            write_node_info(HT_Node_Ptr, EmTemp, EmTemp, 0, 2);
                            break;
                            
                        case 1:
                            EmTemp->put_neigh_proc(1, recv->sender_id);
                            EmTemp->put_neigh_proc(5, recv->sender_id);
                            EmTemp->putneighbor(recv->sender_son2, 1);
                            EmTemp->putneighbor(recv->sender_son1, 5);
                            EmTemp->put_neigh_gen(1, recv->sender_gen + 1); //--999
                            EmTemp->put_neigh_gen(5, recv->sender_gen + 1); //--999
                                    
                            if(recv->sender_order[0] > *EmTemp->get_order())
                                EmTemp->put_order(1, recv->sender_order[0]);
                            if(recv->sender_order[1] > *EmTemp->get_order())
                                EmTemp->put_order(1, recv->sender_order[1]);
                            write_node_info(HT_Node_Ptr, EmTemp, EmTemp, 1, 2);
                            break;
                            
                        case 2:
                            EmTemp->put_neigh_proc(2, recv->sender_id);
                            EmTemp->put_neigh_proc(6, recv->sender_id);
                            EmTemp->putneighbor(recv->sender_son2, 2);
                            EmTemp->putneighbor(recv->sender_son1, 6);
                            EmTemp->put_neigh_gen(2, recv->sender_gen + 1); //--999
                            EmTemp->put_neigh_gen(6, recv->sender_gen + 1); //--999
                                    
                            if(recv->sender_order[0] > *EmTemp->get_order())
                                EmTemp->put_order(2, recv->sender_order[0]);
                            if(recv->sender_order[1] > *EmTemp->get_order())
                                EmTemp->put_order(2, recv->sender_order[1]);
                            write_node_info(HT_Node_Ptr, EmTemp, EmTemp, 2, 2);
                            break;
                            
                        case 3:
                            EmTemp->put_neigh_proc(3, recv->sender_id);
                            EmTemp->put_neigh_proc(7, recv->sender_id);
                            EmTemp->putneighbor(recv->sender_son2, 3);
                            EmTemp->putneighbor(recv->sender_son1, 7);
                            EmTemp->put_neigh_gen(3, recv->sender_gen + 1); //--999
                            EmTemp->put_neigh_gen(7, recv->sender_gen + 1); //--999
                                    
                            if(recv->sender_order[0] > *EmTemp->get_order())
                                EmTemp->put_order(3, recv->sender_order[0]);
                            if(recv->sender_order[1] > *EmTemp->get_order())
                                EmTemp->put_order(3, recv->sender_order[1]);
                            write_node_info(HT_Node_Ptr, EmTemp, EmTemp, 3, 2);
                            break;
                            
                    }
                }
                
                else /*--both sender and receptor are not refined and they are on the same generation--*/
                {
                    if(recv->sender_order[0] > *(EmTemp->get_order() + recv->side))
                        EmTemp->put_order(recv->side, recv->sender_order[0]);
                    p = HT_Node_Ptr->lookup(EmTemp->getNode() + (recv->side + 4) * KEYLENGTH); //-- cc
                    assert(p);
                    Node* NdTemp = (Node*) p;
                    NdTemp->put_order(*(EmTemp->get_order() + recv->side));
                }
            }
            
        }
        
        else //-- sender's generation is diffrent from receptor's
        {
            
            unsigned* ndkey = EmTemp->getNode();
            
            if(recv->sender_gen > EmTemp->get_gen()) //--sender is smaller than receptor
            {
                assert(!recv->sender_refined); //-- debug window
                if(EmTemp->get_refined_flag()) //-- happened only in h-refinement
                {
                    /*-- search, which son of EmTemp? a is the result --*/
                    int a = recv->side;
                    if(a == 7)
                        a = 0;
                    else if(a > 3)
                        a = a - 3;
                    
                    sonP = EmTemp->getson();
                    SonTemp1 = (Element*) (HT_Elem_Ptr->lookup(sonP + a * KEYLENGTH));
                    
                    int start;
                    int end;
                    int mid;
                    
                    /*-- find out which side of this son be modified--*/
                    if(a == recv->side)
                    {
                        start = recv->side;
                        end = start + 1;
                        if(end == 4)
                            end = 0;
                        mid = start + 4;
                        write_node_info_ext(HT_Node_Ptr, SonTemp1, end, mid);
                    }
                    else
                    {
                        start = recv->side - 4;
                        mid = start + 4;
                        write_node_info_ext(HT_Node_Ptr, SonTemp1, start, mid);
                    }
                    
                    SonTemp1->putneighbor(recv->sender, start);
                    SonTemp1->put_neigh_gen(start, recv->sender_gen);
                    SonTemp1->put_neigh_proc(start, recv->sender_id); //--maybe surplus
                                             
                }
                else //-- p enrichment
                {
                    assert(recv->sender_gen == EmTemp->get_gen() + 1); //-- debug window
                            
                    int start = recv->side % 4;
                    
                    Node* NdTemp = (Node*) (HT_Node_Ptr->lookup(ndkey + (start + 4) * KEYLENGTH));
                    
                    if(recv->sender_order[0] > *(EmTemp->get_order() + start))
                        EmTemp->put_order(start, recv->sender_order[0]);
                    
                    int final_order = *(EmTemp->get_order() + start);
                    
                    NdTemp->put_order(final_order);
                }
                
            }
            
            if(recv->sender_gen < EmTemp->get_gen()) //--sender is bigger than receptor
            {
                if(recv->sender_refined)
                {
                    assert(recv->side < 4);
                    int start = recv->side;
                    int end = start + 1;
                    if(end == 4)
                        end = 0;
                    
                    keyP = EmTemp->getNode();
                    Node* NdTemp = (Node*) (HT_Node_Ptr->lookup(keyP + start * KEYLENGTH));
                    
                    if(NdTemp->getinfo() == S_S_CON)
                    {
                        EmTemp->putneighbor(recv->sender_son1, start);
                        write_node_info_ext(HT_Node_Ptr, EmTemp, start, start + 4);
                        
                    }
                    else
                    {
                        int mid = -1;
                        NdTemp = (Node*) (HT_Node_Ptr->lookup(keyP + end * KEYLENGTH));
                        EmTemp->putneighbor(recv->sender_son2, start);
                        if(end == 0)
                            mid = 7;
                        else
                            mid = end + 3;
                        write_node_info_ext(HT_Node_Ptr, EmTemp, end, mid);
                        
                    }
                    
                    EmTemp->put_neigh_gen(start, recv->sender_gen + 1);
                    EmTemp->put_neigh_proc(start, recv->sender_id);
                    
                }
                else
                {
                    assert(recv->sender_gen == EmTemp->get_gen() - 1); //-- debug window
                            
                    int start = recv->side;
                    int end = start + 1;
                    if(end == 4)
                        end = 0;
                    
                    Node* NdTemp = (Node*) (HT_Node_Ptr->lookup(ndkey + start * KEYLENGTH));
                    if(NdTemp->getinfo() != S_C_CON)
                    {
                        NdTemp = (Node*) (HT_Node_Ptr->lookup(ndkey + end * KEYLENGTH));
                        //assert(NdTemp->getinfo()==S_C_CON);
                    }
                    
                    if(recv->sender_order[0] > *(EmTemp->get_order() + start))
                        EmTemp->put_order(start, recv->sender_order[0]);
                    
                    int final_order = *(EmTemp->get_order() + start);
                    
                    NdTemp->put_order(final_order);
                }
                
            }
            
        }
        
        recv = recv->next;
    }
}