Ejemplo n.º 1
0
void mlk_prcblk_delete(mlk_ctldata_ptr_t ctl,
		       mlk_shrblk_ptr_t d,
		       uint4 pid)
{
	mlk_prcblk_ptr_t	pr;
	sm_int_ptr_t		prpt;

	for (prpt = &d->pending; *prpt; )
	{
		pr = (mlk_prcblk_ptr_t)R2A(*prpt);
		if ((pr->process_id == pid) && (--pr->ref_cnt <= 0))
		{
				pr->ref_cnt = 0;
				if (pr->next == 0)
					*prpt = 0;
				else
					A2R(*prpt, R2A(pr->next));
				memset(pr, 0, sizeof(*pr));
				A2R(pr->next, R2A(ctl->prcfree));
				A2R(ctl->prcfree, pr);
				assert(ctl->prcfree >= 0);
				ctl->prccnt++;
				if (0 != pid)
					break;
		} else
				prpt = &pr->next;
	}
	return;
}
Ejemplo n.º 2
0
void Camera::selfRotate(double x, double y)
{
	angleX += x;
	if(angleX > 180){
		angleX = angleX - 360;
	}
	if (angleX < -180) {
		angleX = angleX + 360;
	}
	if (angleY + y>90||angleY + y<-90) {
		y = 0;
	}
	angleY += y;
	Vector3d zero;
	zero.x = 0.0;
	zero.y = 0.0;
	zero.z = 0.0;
	Vector3d haxis;
	Vector3d vaxis;
	Vector3d vz = position - center;
	haxis = cross(up, vz);
	haxis.normalize();
	vaxis.x = 0.0;
	vaxis.y = 1.0;
	vaxis.z = 0.0;
	Vector3d mid=rotate(haxis, position, A2R(y), center);
	mid = rotate(vaxis, position, A2R(x), mid);
	center = mid;
	mid = rotate(haxis, zero, A2R(y), up);
	mid = rotate(vaxis, zero, A2R(x), mid);
	up = mid;
}
Ejemplo n.º 3
0
void initialize ()
{
		int i;
		float angle=(30.f/360)*2*(3.141592);
		float range = 8;
		glMatrixMode(GL_PROJECTION);												// select projection matrix
		glViewport(0, 0, win.width, win.height);									// set the viewport
		glMatrixMode(GL_PROJECTION);												// set matrix mode
		glLoadIdentity();															// reset projection matrix
		GLfloat aspect = (GLfloat) win.width / win.height;
		gluPerspective(win.field_of_view_angle, aspect, win.z_near, win.z_far);		// set up a perspective projection matrix
		glMatrixMode(GL_MODELVIEW);													// specify which matrix is the current matrix
		glShadeModel( GL_SMOOTH );
		glClearDepth( 1.0f );														// specify the clear value for the depth buffer
		glEnable( GL_DEPTH_TEST );
		glDepthFunc( GL_LEQUAL );
		glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );						// specify implementation-specific hints
		glClearColor(0.0, 0.0, 0.0, 1.0);											// specify clear values for the color buffers

		points = (p2d*)malloc(sizeof(p2d)*pointnum);
		
		for (i=0; i<pointnum; i++)
		{
				points[i] = createp2d(linewidth * (i-pointnum/2), powf(-1,  (float)(i%2))* abs( ((float)(rand()%((int)range*10)))/(range*10)*range - range/2));
		}
		exlines = (p2d**)malloc(sizeof(p2d*)*exlinesnum);
		
		
		moonpoints = (p2d*)malloc(sizeof(p2d)*moonpnum);
		for(i=0;i<moonpnum;i++)
		{
				moonpoints[i] = createp2d(cosf(angle + A2R(60.f)*i) * moonradius, sinf(angle+A2R(60.f)*i) * moonradius);
				printf("%f %f\n", moonpoints[i][0], moonpoints[i][1]);
		}

		moonpoints[0][1]*=0.8;
		moonpoints[moonpnum-1][1]*=0.8;
		moonpoints[0][0]*=0.5;
		moonpoints[moonpnum-1][0]*=0.5;
		
		moonpoints[2][0] *= 1.4f;
		moonpoints[3][0] *= 1.4f;
		moonexlines = (p2d**)malloc(sizeof(p2d*)*exmoonlinesnum);
}
Ejemplo n.º 4
0
void mlk_prcblk_add(gd_region *reg,
		    mlk_ctldata_ptr_t ctl,
		    mlk_shrblk_ptr_t d,
		    uint4 pid)
{
	mlk_prcblk_ptr_t	pr;
	sm_int_ptr_t		prpt;
	int			lcnt;

	for (prpt = &d->pending, lcnt = FILE_INFO(reg)->s_addrs.hdr->lock_space_size / PRC_FACTOR;
			*prpt && lcnt; prpt = &pr->next, lcnt--)
	{
		pr = (mlk_prcblk_ptr_t)R2A(*prpt);
		if (pr->process_id == pid)
		{
			pr->ref_cnt++;
			return;
		}
	}
	if (!lcnt)
		GTMASSERT;
	if (ctl->prccnt < 1)
	{
		mlk_shrclean(reg, ctl, (mlk_shrblk_ptr_t)R2A(ctl->blkroot));
		if (ctl->prccnt < 1)
			return;
	}
	ctl->prccnt--;
	pr = (mlk_prcblk_ptr_t)R2A(ctl->prcfree);
	if (0 == pr->next)
	{
		assert(0 == ctl->prccnt);
		ctl->prcfree = 0;
	} else
		A2R(ctl->prcfree, R2A(pr->next));
	A2R(*prpt, pr);
	pr->process_id = pid;
	pr->ref_cnt = 1;
	pr->next = pr->unlock = 0;
	return;
}
Ejemplo n.º 5
0
bool	mlk_shrblk_delete_if_empty(mlk_ctldata_ptr_t ctl,
				   mlk_shrblk_ptr_t d)
{
	mlk_shrblk_ptr_t	r, l, p;
	mlk_shrsub_ptr_t	sub;


	if (d->children != 0  ||  d->owner != 0  ||  d->pending != 0)
		return FALSE;

	if (d->parent == 0)
		p = NULL;
	else
		p = (mlk_shrblk_ptr_t)R2A(d->parent);

	l = (mlk_shrblk_ptr_t)R2A(d->lsib);
	r = (mlk_shrblk_ptr_t)R2A(d->rsib);
	if (d == r)
		if (p == NULL)
			ctl->blkroot = 0;
		else
			p->children = 0;
	else
	{
		assert(d != l);
		A2R(r->lsib, l);
		A2R(l->rsib, r);
		if (p != NULL  &&  (mlk_shrblk_ptr_t)R2A(p->children) == d)
			A2R(p->children, r);
		else
			if ((mlk_shrblk_ptr_t)R2A(ctl->blkroot) == d)
				A2R(ctl->blkroot, r);
	}

	sub = (mlk_shrsub_ptr_t)R2A(d->value);
	PUT_ZERO(sub->backpointer);

	p = (mlk_shrblk_ptr_t)R2A(ctl->blkfree);
	memset(d, 0, SIZEOF(mlk_shrblk));
	A2R(d->rsib, p);

	A2R(ctl->blkfree, d);
	++ctl->blkcnt;

	return TRUE;

}
Ejemplo n.º 6
0
inline void LUnb( DistMatrix<R>& A )
{
#ifndef RELEASE
    PushCallStack("bidiag::LUnb");
    if( A.Height() > A.Width() )
        throw std::logic_error("A must be at least as wide as it is tall");
#endif
    const Grid& g = A.Grid();

    // Matrix views 
    DistMatrix<R>
        ATL(g), ATR(g),  A00(g), a01(g),     A02(g),  alpha21T(g), a1R(g),
        ABL(g), ABR(g),  a10(g), alpha11(g), a12(g),  a21B(g),     A2R(g),
                         A20(g), a21(g),     A22(g);

    // Temporary matrices
    DistMatrix<R,MC,  STAR> a21_MC_STAR(g);
    DistMatrix<R,STAR,MR  > a1R_STAR_MR(g);
    DistMatrix<R,MR,  STAR> x12Trans_MR_STAR(g);
    DistMatrix<R,MC,  STAR> w21_MC_STAR(g);

    PushBlocksizeStack( 1 );
    PartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 );
    while( ATL.Width() < A.Width() )
    {
        RepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ a01,     A02,
         /*************/ /**********************/
               /**/       a10, /**/ alpha11, a12,
          ABL, /**/ ABR,  A20, /**/ a21,     A22 );

        View1x2( a1R, alpha11, a12 );
        View1x2( A2R, a21, A22 );

        a21_MC_STAR.AlignWith( A22 );
        a1R_STAR_MR.AlignWith( A2R );
        x12Trans_MR_STAR.AlignWith( A22 );
        w21_MC_STAR.AlignWith( A2R );
        Zeros( a12.Width(), 1, x12Trans_MR_STAR );
        Zeros( a21.Height(), 1, w21_MC_STAR );
        const bool thisIsMyRow = ( g.Row() == alpha11.ColAlignment() );
        const bool thisIsMyCol = ( g.Col() == alpha11.RowAlignment() );
        const bool nextIsMyRow = ( g.Row() == a21.ColAlignment() );
        //--------------------------------------------------------------------//

        // Find tauP, u, and epsilonP such that
        //     I - tauP | 1 | | 1, v^T | | alpha11 | = | epsilonP |
        //              | v |            |   a12^T | = |    0     |
        const R tauP = Reflector( alpha11, a12 );
        R epsilonP=0;
        if( thisIsMyCol && thisIsMyRow )
            epsilonP = alpha11.GetLocal(0,0);

        // Set a1R^T = | 1 | and form w21 := A2R a1R^T = A2R | 1 |
        //             | v |                                 | v |
        alpha11.Set(0,0,R(1));
        a1R_STAR_MR = a1R;
        LocalGemv( NORMAL, R(1), A2R, a1R_STAR_MR, R(0), w21_MC_STAR );
        w21_MC_STAR.SumOverRow();

        // A2R := A2R - tauP w21 a1R
        //      = A2R - tauP A2R a1R^T a1R
        //      = A2R (I - tauP a1R^T a1R)
        LocalGer( -tauP, w21_MC_STAR, a1R_STAR_MR, A2R );

        // Put epsilonP back instead of the temporary value, 1
        if( thisIsMyCol && thisIsMyRow )
            alpha11.SetLocal(0,0,epsilonP);

        if( A22.Height() != 0 )
        {
            // Expose the subvector we seek to zero, a21B
            PartitionDown
            ( a21, alpha21T,
                   a21B );

            // Find tauQ, u, and epsilonQ such that
            //     I - tauQ | 1 | | 1, u^T | | alpha21T | = | epsilonQ |
            //              | u |            | a21B     | = |    0     |
            const R tauQ = Reflector( alpha21T, a21B );
            R epsilonQ=0;
            if( nextIsMyRow && thisIsMyCol )
                epsilonQ = alpha21T.GetLocal(0,0);

            // Set a21 = | 1 | and form x12^T = (a21^T A22)^T = A22^T a21
            //           | u |  
            alpha21T.Set(0,0,R(1));
            a21_MC_STAR = a21;
            LocalGemv
            ( TRANSPOSE, R(1), A22, a21_MC_STAR, R(0), x12Trans_MR_STAR );
            x12Trans_MR_STAR.SumOverCol();

            // A22 := A22 - tauQ a21 x12
            //      = A22 - tauQ a21 a21^T A22
            //      = (I - tauQ a21 a21^T) A22
            LocalGer( -tauQ, a21_MC_STAR, x12Trans_MR_STAR, A22 );

            // Put epsilonQ back instead of the temporary value, 1
            if( nextIsMyRow && thisIsMyCol )
                alpha21T.SetLocal(0,0,epsilonQ);
        }
        //--------------------------------------------------------------------//
        a1R_STAR_MR.FreeAlignments();
        a21_MC_STAR.FreeAlignments();
        x12Trans_MR_STAR.FreeAlignments();
        w21_MC_STAR.FreeAlignments();

        SlidePartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, a01,     /**/ A02,
               /**/       a10, alpha11, /**/ a12,
         /*************/ /**********************/
          ABL, /**/ ABR,  A20, a21,     /**/ A22 );
    }
    PopBlocksizeStack();
#ifndef RELEASE
    PopCallStack();
#endif
}
Ejemplo n.º 7
0
inline void LUnb
( DistMatrix<Complex<R> >& A, 
  DistMatrix<Complex<R>,MD,STAR>& tP,
  DistMatrix<Complex<R>,MD,STAR>& tQ )
{
#ifndef RELEASE
    PushCallStack("bidiag::LUnb");
#endif
    const int tPHeight = A.Height();
    const int tQHeight = std::max(A.Height()-1,0);
#ifndef RELEASE
    if( A.Grid() != tP.Grid() || tP.Grid() != tQ.Grid() )
        throw std::logic_error("Process grids do not match");
    if( A.Height() > A.Width() )
        throw std::logic_error("A must be at least as wide as it is tall");
    if( tP.Viewing() && (tP.Height() != tPHeight || tP.Width() != 1) )
        throw std::logic_error("tP is the wrong height");
    if( tQ.Viewing() && (tQ.Height() != tQHeight || tQ.Width() != 1) )
        throw std::logic_error("tQ is the wrong height");
#endif
    typedef Complex<R> C;
    const Grid& g = A.Grid();

    if( !tP.Viewing() )
        tP.ResizeTo( tPHeight, 1 );
    if( !tQ.Viewing() )
        tQ.ResizeTo( tQHeight, 1 );

    // Matrix views 
    DistMatrix<C>
        ATL(g), ATR(g),  A00(g), a01(g),     A02(g),  alpha21T(g), a1R(g),
        ABL(g), ABR(g),  a10(g), alpha11(g), a12(g),  a21B(g),     A2R(g),
                         A20(g), a21(g),     A22(g);

    // Temporary matrices
    DistMatrix<C,MC,  STAR> a21_MC_STAR(g);
    DistMatrix<C,STAR,MR  > a1R_STAR_MR(g);
    DistMatrix<C,MR,  STAR> x12Adj_MR_STAR(g);
    DistMatrix<C,MC,  STAR> w21_MC_STAR(g);

    PushBlocksizeStack( 1 );
    PartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 );
    while( ATL.Width() < A.Width() )
    {
        RepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ a01,     A02,
         /*************/ /**********************/
               /**/       a10, /**/ alpha11, a12,
          ABL, /**/ ABR,  A20, /**/ a21,     A22 );

        View1x2( a1R, alpha11, a12 );
        View1x2( A2R, a21, A22 );

        a21_MC_STAR.AlignWith( A22 );
        a1R_STAR_MR.AlignWith( A2R );
        x12Adj_MR_STAR.AlignWith( A22 );
        w21_MC_STAR.AlignWith( A2R );
        Zeros( a12.Width(), 1, x12Adj_MR_STAR );
        Zeros( a21.Height(), 1, w21_MC_STAR );
        const bool thisIsMyRow = ( g.Row() == alpha11.ColAlignment() );
        const bool thisIsMyCol = ( g.Col() == alpha11.RowAlignment() );
        const bool nextIsMyRow = ( g.Row() == a21.ColAlignment() );
        //--------------------------------------------------------------------//

        // Due to deficiencies in the BLAS ?gemv routines, this section is
        // easier if we temporary conjugate a1R = | alpha11, a12 |
        Conjugate( a1R );

        // Find tauP, u, and epsilonP such that
        //     I - conj(tauP) | 1 | | 1, v^H | | alpha11 | = | epsilonP |
        //                    | v |            |   a12^T | = |    0     |
        const C tauP = Reflector( alpha11, a12 );
        tP.Set(A00.Height(),0,tauP);
        C epsilonP=0;
        if( thisIsMyCol && thisIsMyRow )
            epsilonP = alpha11.GetLocal(0,0);

        // Set a1R^T = | 1 | and form w21 := A2R a1R^T = A2R | 1 |
        //             | v |                                 | v |
        alpha11.Set(0,0,C(1));
        a1R_STAR_MR = a1R;
        LocalGemv( NORMAL, C(1), A2R, a1R_STAR_MR, C(0), w21_MC_STAR );
        w21_MC_STAR.SumOverRow();

        // A2R := A2R - tauP w21 conj(a1R)
        //      = A2R - tauP A2R a1R^T conj(a1R)
        //      = A2R conj(I - conj(tauP) a1R^H a1R)
        // which compensates for the fact that the reflector was generated
        // on the conjugated a1R
        LocalGer( -tauP, w21_MC_STAR, a1R_STAR_MR, A2R );

        // Put epsilonP back instead of the temporary value, 1
        if( thisIsMyCol && thisIsMyRow )
            alpha11.SetLocal(0,0,epsilonP);

        // Undo the temporary conjugation
        Conjugate( a1R );

        if( A22.Height() != 0 )
        {
            // Expose the subvector we seek to zero, a21B
            PartitionDown
            ( a21, alpha21T,
                   a21B );

            // Find tauQ, u, and epsilonQ such that
            //     I - conj(tauQ) | 1 | | 1, u^H | | alpha21T | = | epsilonQ |
            //                    | u |            | a21B     | = |    0     |
            const C tauQ = Reflector( alpha21T, a21B );
            tQ.Set(A00.Height(),0,tauQ);
            C epsilonQ=0;
            if( nextIsMyRow && thisIsMyCol )
                epsilonQ = alpha21T.GetLocal(0,0);

            // Set a21 = | 1 | and form x12^H = (a21^H A22)^H = A22^H a21
            //           | u |  
            alpha21T.Set(0,0,C(1));
            a21_MC_STAR = a21;
            LocalGemv( ADJOINT, C(1), A22, a21_MC_STAR, C(0), x12Adj_MR_STAR );
            x12Adj_MR_STAR.SumOverCol();

            // A22 := A22 - conj(tauQ) a21 x12
            //      = A22 - conj(tauQ) a21 a21^H A22
            //      = (I - conj(tauQ) a21 a21^H) A22
            LocalGer( -Conj(tauQ), a21_MC_STAR, x12Adj_MR_STAR, A22 );

            // Put epsilonQ back instead of the temporary value, 1
            if( nextIsMyRow && thisIsMyCol )
                alpha21T.SetLocal(0,0,epsilonQ);
        }
        //--------------------------------------------------------------------//
        a21_MC_STAR.FreeAlignments();
        a1R_STAR_MR.FreeAlignments();
        x12Adj_MR_STAR.FreeAlignments();
        w21_MC_STAR.FreeAlignments();

        SlidePartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, a01,     /**/ A02,
               /**/       a10, alpha11, /**/ a12,
         /*************/ /**********************/
          ABL, /**/ ABR,  A20, a21,     /**/ A22 );
    }
    PopBlocksizeStack();
#ifndef RELEASE
    PopCallStack();
#endif
}