Example #1
0
int main()
{
int n,c1,c2,c3,i;
double cos;
	printf("Enter the number: ");
	scanf("%d",&n);
	int *ar;
	int *br;
	
	ar = (int *)malloc(sizeof(int)*n);
	for (i=0;i<n;i++) 
	{
	printf("Enter the element of array: ");
	scanf("%d",&ar[i]);
	}
	br = (int *)malloc(sizeof(int)*n);
	printf("\n");
	for (i=0;i<n;i++) 
	{
	printf("Enter the element of array: ");
	scanf("%d",&br[i]);
	}
	Scal(ar,ar,n,&c1);
	Scal(br,br,n,&c2);
	if ((c1==0)&&(c2==0)) printf("1");
	else if ((c1==0)||(c2==0)) printf("0");
	else 
	{
	Scal(ar,br,n,&c3);
	cos = c3/(sqrt(c1)*sqrt(c2));
	}
	if (cos==1) printf("1");
	else printf("0");
	return 0;
}
Example #2
0
 /* Prototype implementation for specialized functions */
 void Vector::AddTwoVectorsImpl(Number a, const Vector& v1,
                                Number b, const Vector& v2, Number c)
 {
   if (c==0.) {
     if (a==1.) {
       Copy(v1);
       if (b!=0.) {
         Axpy(b, v2);
       }
     }
     else if (a==0.) {
       if (b==0.) {
         Set(0.);
       }
       else {
         Copy(v2);
         if (b!=1.) {
           Scal(b);
         }
       }
     }
     else {
       if (b==1.) {
         Copy(v2);
         Axpy(a, v1);
       }
       else if (b==0.) {
         Copy(v1);
         Scal(a);
       }
       else {
         Copy(v1);
         Scal(a);
         Axpy(b, v2);
       }
     }
   }
   else { /* c==0. */
     if (c!=1.) {
       Scal(c);
     }
     if (a!=0.) {
       Axpy(a, v1);
     }
     if (b!=0.) {
       Axpy(b, v2);
     }
   }
 }
Example #3
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   #ifdef OPENCL_API
     auto queue_plain = queue();
     auto event = cl_event{};
     auto status = Scal(args.n, args.alpha,
                        buffers.x_vec(), args.x_offset, args.x_inc,
                        &queue_plain, &event);
     if (status == StatusCode::kSuccess) { clWaitForEvents(1, &event); clReleaseEvent(event); }
   #elif CUDA_API
     auto status = Scal(args.n, args.alpha,
                        buffers.x_vec(), args.x_offset, args.x_inc,
                        queue.GetContext()(), queue.GetDevice()());
     cuStreamSynchronize(queue());
   #endif
   return status;
 }
Example #4
0
Vettore Piano::ProjOnNorm(Vettore *v){
  double Len = 0.;
  for(int d=0;d<v->NDim;d++){
    Len += v->x[d]*Norm[d];
  }
  Vettore Scal(Len*Norm[0],Len*Norm[1],Len*Norm[2]);
  return Scal;
}
Example #5
0
void Gemv
( char trans, int m, int n,
  T alpha, const T* A, int lda, const T* x, int incx,
  T beta,        T* y, int incy )
{
    if( trans == 'N' )
    {
        if( m > 0 && n == 0 && beta == 0 )
        {
            for( int i=0; i<m; ++i )
                y[i*incy] = 0;   
            return;
        }
        Scal( m, beta, y, incy );
        for( int i=0; i<m; ++i ) 
            for( int j=0; j<n; ++j )
                y[i*incy] += alpha*A[i+j*lda]*x[j*incx];
    }
    else if( trans == 'T' ) 
    {
        if( n > 0 && m == 0 && beta == 0 )
        {
            for( int i=0; i<n; ++i )
                y[i*incy] = 0;   
            return;
        }
        Scal( n, beta, y, incy );
        for( int i=0; i<n; ++i ) 
            for( int j=0; j<m; ++j )
                y[i*incy] += alpha*A[j+i*lda]*x[j*incx];
    }
    else
    {
        if( n > 0 && m == 0 && beta == 0 )
        {
            for( int i=0; i<n; ++i )
                y[i*incy] = 0;   
            return;
        }
        Scal( n, beta, y, incy );
        for( int i=0; i<n; ++i ) 
            for( int j=0; j<m; ++j )
                y[i*incy] += alpha*Conj(A[j+i*lda])*x[j*incx];
    }
}
Example #6
0
 // Describes how to run the CLBlast routine
 static StatusCode RunRoutine(const Arguments<T> &args, Buffers<T> &buffers, Queue &queue) {
   auto queue_plain = queue();
   auto event = cl_event{};
   auto status = Scal(args.n, args.alpha,
                      buffers.x_vec(), args.x_offset, args.x_inc,
                      &queue_plain, &event);
   clWaitForEvents(1, &event);
   return status;
 }
Example #7
0
/*!
 *\brief Mergesort na tablicy
 *
 *\param[in] tablica-struktura przechowujaca tablice dynamiczna
 *\param[in] lewy- lewa granica sortowania (numer indeksu)
 *\param[in] prawy- prawa granica sortowania (numer indeksu)
 */
void MSort::Mergesort(Tab &tablica,int lewy,int prawy){
  if(prawy<=lewy) return; 

  int srodek = (prawy+lewy)/2;
  Mergesort(tablica,lewy,srodek); 
  Mergesort(tablica,srodek+1,prawy);

  Scal(tablica,lewy,srodek,prawy);

}
Example #8
0
void Vector::normalize() {
  Scal d = norm();
  Scal t;
  

  if (d != Scal(0.0f)) {
    t= 1/d;
    x *= t;
    y *= t;
    z *= t;
  }
}
Example #9
0
bool				ICoDF_HTM::HTM::CheckPointInTriangle(std::pair<double, double> A,
						     std::pair<double, double> B,
						     std::pair<double, double> C,
						     std::pair<double, double> P)
{
  std::pair<double, double> 	v0 = CalcCoordPoint(C, A);
  std::pair<double, double> 	v1 = CalcCoordPoint(B, A);
  std::pair<double, double> 	v2 = CalcCoordPoint(P, A);

  const double			dot00 = Scal(v0, v0);
  const double			dot01 = Scal(v0, v1);
  const double			dot02 = Scal(v0, v2);
  const double			dot11 = Scal(v1, v1);
  const double			dot12 = Scal(v1, v2);

  const double       		invDenom = 1 / (dot00 * dot11 - dot01 * dot01);

  const double       		u = (dot11 * dot02 - dot01 * dot12) * invDenom;
  const double       		v = (dot00 * dot12 - dot01 * dot02) * invDenom;

  return ((u >= 0) && (v >= 0) && (u + v < 1));
}
Example #10
0
Vector Vector::normalized() const{
  Scal d = norm();
  Scal t;

  Vector v = *this;

  if (d != Scal(0)) {
    t= 1/d;
    v.x *= t;
    v.y *= t;
    v.z *= t;
  }

  return v;
}
Example #11
0
inline void
LU( Matrix<F>& A )
{
#ifndef RELEASE
    PushCallStack("LU");
#endif
    // Matrix views 
    Matrix<F>
        ATL, ATR,  A00, a01,     A02,  alpha21T,
        ABL, ABR,  a10, alpha11, a12,  a21B,
                   A20, a21,     A22;

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

        //--------------------------------------------------------------------//
        F alpha = alpha11.Get(0,0);
        if( alpha == static_cast<F>(0) )
            throw SingularMatrixException();
        Scal( static_cast<F>(1)/alpha, a21 );
        Geru( (F)-1, a21, a12, A22 );
        //--------------------------------------------------------------------//

        SlidePartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, a01,     /**/ A02,
               /**/       a10, alpha11, /**/ a12,
         /*************/ /**********************/
          ABL, /**/ ABR,  A20, a21,     /**/ A22 );
    }
    PopBlocksizeStack();
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #12
0
inline void
SVD
( DistMatrix<F>& A,
  DistMatrix<typename Base<F>::type,VR,STAR>& s,
  DistMatrix<F>& V,
  double heightRatio )
{
#ifndef RELEASE
    PushCallStack("SVD");
    if( heightRatio <= 1.0 )
        throw std::logic_error("Nonsensical switchpoint for SVD");
#endif
    typedef typename Base<F>::type Real;

    // Check if we need to rescale the matrix, and do so if necessary
    bool needRescaling;
    Real scale;
    svd::CheckScale( A, needRescaling, scale );
    if( needRescaling )
        Scale( scale, A );

    // TODO: Switch between different algorithms. For instance, starting 
    //       with a QR decomposition of tall-skinny matrices.
    if( A.Height() >= A.Width() )
    {
        svd::SVDUpper( A, s, V, heightRatio );
    }
    else
    {
        // Lower bidiagonalization is not yet supported, so we instead play a 
        // trick to get the SVD of A.
        Adjoint( A, V );
        svd::SVDUpper( V, s, A, heightRatio );
    }

    // Rescale the singular values if necessary
    if( needRescaling )
        Scal( 1/scale, s );
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #13
0
inline void
SingularValues
( DistMatrix<F>& A,
  DistMatrix<typename Base<F>::type,VR,STAR>& s,
  double heightRatio )
{
#ifndef RELEASE
    PushCallStack("SingularValues");
#endif
    typedef typename Base<F>::type R;

    // Check if we need to rescale the matrix, and do so if necessary
    bool needRescaling;
    R scale;
    svd::CheckScale( A, needRescaling, scale );
    if( needRescaling )
        Scale( scale, A );

    // TODO: Switch between different algorithms. For instance, starting 
    //       with a QR decomposition of tall-skinny matrices.
    if( A.Height() >= A.Width() )
    {
        svd::SingularValuesUpper( A, s, heightRatio );
    }
    else
    {
        // Lower bidiagonalization is not yet supported, so we instead play a 
        // trick to get the SVD of A.
        DistMatrix<F> AAdj( A.Grid() );
        Adjoint( A, AAdj );
        svd::SingularValuesUpper( AAdj, s, heightRatio );
    }

    // Rescale the singular values if necessary
    if( needRescaling )
        Scal( 1/scale, s );
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #14
0
inline void
internal::HemmLLC
( T alpha, const DistMatrix<T,MC,MR>& A,
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::HemmLLC");
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error
        ("{A,B,C} must be distributed over the same grid");
#endif
    const Grid& g = A.Grid();

    // Matrix views
    DistMatrix<T,MC,MR> 
        ATL(g), ATR(g),  A00(g), A01(g), A02(g),  AColPan(g),
        ABL(g), ABR(g),  A10(g), A11(g), A12(g),  ARowPan(g),
                         A20(g), A21(g), A22(g);

    DistMatrix<T,MC,MR> 
        BT(g),  B0(g),
        BB(g),  B1(g),
                B2(g);

    DistMatrix<T,MC,MR> 
        CT(g),  C0(g),  CAbove(g),
        CB(g),  C1(g),  CBelow(g),
                C2(g);

    // Temporary distributions
    DistMatrix<T,MC,  STAR> AColPan_MC_STAR(g);
    DistMatrix<T,STAR,MC  > ARowPan_STAR_MC(g);
    DistMatrix<T,MR,  STAR> B1Adj_MR_STAR(g);

    // Start the algorithm
    Scal( beta, C );
    LockedPartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 );
    LockedPartitionDown
    ( B, BT,
         BB, 0 );
    PartitionDown
    ( C, CT,
         CB, 0 );
    while( CB.Height() > 0 )
    {
        LockedRepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ A01, A02,
         /*************/ /******************/
               /**/       A10, /**/ A11, A12,
          ABL, /**/ ABR,  A20, /**/ A21, A22 );

        LockedRepartitionDown
        ( BT,  B0,
         /**/ /**/
               B1,
          BB,  B2 );

        RepartitionDown
        ( CT,  C0,
         /**/ /**/
               C1,
          CB,  C2 );

        ARowPan.LockedView1x2( A10, A11 );

        AColPan.LockedView2x1
        ( A11,
          A21 );

        CAbove.View2x1
        ( C0,
          C1 );

        CBelow.View2x1
        ( C1,
          C2 );

        AColPan_MC_STAR.AlignWith( CBelow );
        ARowPan_STAR_MC.AlignWith( CAbove );
        B1Adj_MR_STAR.AlignWith( C );
        //--------------------------------------------------------------------//
        AColPan_MC_STAR = AColPan;
        ARowPan_STAR_MC = ARowPan;
        MakeTrapezoidal( LEFT,  LOWER,  0, AColPan_MC_STAR );
        MakeTrapezoidal( RIGHT, LOWER, -1, ARowPan_STAR_MC );

        B1Adj_MR_STAR.AdjointFrom( B1 );

        internal::LocalGemm
        ( NORMAL, ADJOINT, 
          alpha, AColPan_MC_STAR, B1Adj_MR_STAR, (T)1, CBelow );

        internal::LocalGemm
        ( ADJOINT, ADJOINT, 
          alpha, ARowPan_STAR_MC, B1Adj_MR_STAR, (T)1, CAbove );
        //--------------------------------------------------------------------//
        AColPan_MC_STAR.FreeAlignments();
        ARowPan_STAR_MC.FreeAlignments();
        B1Adj_MR_STAR.FreeAlignments();

        SlideLockedPartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, A01, /**/ A02,
               /**/       A10, A11, /**/ A12,
         /*************/ /******************/
          ABL, /**/ ABR,  A20, A21, /**/ A22 );

        SlideLockedPartitionDown
        ( BT,  B0,
               B1,
         /**/ /**/
          BB,  B2 );

        SlidePartitionDown
        ( CT,  C0,
               C1,
         /**/ /**/
          CB,  C2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #15
0
Scal Vector::norm() const{
  auto r = (x*x+y*y+z*z);
  return Scal(std::sqrt(r));
}
Example #16
0
inline void
internal::GemmTNB
( Orientation orientationOfA,
  T alpha, const DistMatrix<T,MC,MR>& A,
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::GemmTNB");
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error
        ("{A,B,C} must be distributed over the same grid");
    if( orientationOfA == NORMAL )
        throw std::logic_error("GemmTNB assumes A is (Conjugate)Transposed");
    if( A.Width()  != C.Height() ||
        B.Width()  != C.Width()  ||
        A.Height() != B.Height()   )
    {
        std::ostringstream msg;
        msg << "Nonconformal GemmTNB: \n"
            << "  A ~ " << A.Height() << " x " << A.Width() << "\n"
            << "  B ~ " << B.Height() << " x " << B.Width() << "\n"
            << "  C ~ " << C.Height() << " x " << C.Width() << "\n";
        throw std::logic_error( msg.str() );
    }
#endif
    const Grid& g = A.Grid();

    // Matrix views
    DistMatrix<T,MC,MR> AL(g), AR(g),
                        A0(g), A1(g), A2(g);

    DistMatrix<T,MC,MR> CT(g),  C0(g),
                        CB(g),  C1(g),
                                C2(g);

    // Temporary distributions
    DistMatrix<T,MC,STAR> A1_MC_STAR(g);
    DistMatrix<T,STAR,MR> D1_STAR_MR(g);

    // Start the algorithm
    Scal( beta, C );
    LockedPartitionRight( A, AL, AR, 0 );
    PartitionDown
    ( C, CT,
         CB, 0 );
    while( AR.Width() > 0 )
    {
        LockedRepartitionRight
        ( AL, /**/     AR,
          A0, /**/ A1, A2 );

        RepartitionDown
        ( CT,  C0,
         /**/ /**/
               C1,
          CB,  C2 );

        A1_MC_STAR.AlignWith( B );
        D1_STAR_MR.AlignWith( B );
        D1_STAR_MR.ResizeTo( C1.Height(), C1.Width() );
        //--------------------------------------------------------------------//
        A1_MC_STAR = A1; // A1[MC,*] <- A1[MC,MR]

        // D1[*,MR] := alpha (A1[MC,*])^T B[MC,MR]
        //           = alpha (A1^T)[*,MC] B[MC,MR]
        internal::LocalGemm
        ( orientationOfA, NORMAL, alpha, A1_MC_STAR, B, (T)0, D1_STAR_MR );

        // C1[MC,MR] += scattered result of D1[*,MR] summed over grid cols
        C1.SumScatterUpdate( (T)1, D1_STAR_MR );
        //--------------------------------------------------------------------//
        A1_MC_STAR.FreeAlignments();
        D1_STAR_MR.FreeAlignments();

        SlideLockedPartitionRight
        ( AL,     /**/ AR,
          A0, A1, /**/ A2 );

        SlidePartitionDown
        ( CT,  C0,
               C1,
         /**/ /**/
          CB,  C2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #17
0
inline void
internal::GemmTNC
( Orientation orientationOfA,
  T alpha, const DistMatrix<T,MC,MR>& A,
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::GemmTNC");
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error
        ("{A,B,C} must be distributed over the same grid");
    if( orientationOfA == NORMAL )
        throw std::logic_error("GemmTNC assumes A is (Conjugate)Transposed");
    if( A.Width()  != C.Height() ||
        B.Width()  != C.Width()  ||
        A.Height() != B.Height()   )
    {
        std::ostringstream msg;
        msg << "Nonconformal GemmTNC: \n"
            << "  A ~ " << A.Height() << " x " << A.Width() << "\n"
            << "  B ~ " << B.Height() << " x " << B.Width() << "\n"
            << "  C ~ " << C.Height() << " x " << C.Width() << "\n";
        throw std::logic_error( msg.str().c_str() );
    }
#endif
    const Grid& g = A.Grid();

    // Matrix views
    DistMatrix<T,MC,MR> AT(g),  A0(g),
                        AB(g),  A1(g),
                                A2(g);

    DistMatrix<T,MC,MR> BT(g),  B0(g),
                        BB(g),  B1(g),
                                B2(g);

    // Temporary distributions
    DistMatrix<T,STAR,MC> A1_STAR_MC(g);
    DistMatrix<T,STAR,MR> B1_STAR_MR(g);

    // Start the algorithm
    Scal( beta, C );
    LockedPartitionDown
    ( A, AT,
         AB, 0 );
    LockedPartitionDown
    ( B, BT,
         BB, 0 );
    while( AB.Height() > 0 )
    {
        LockedRepartitionDown
        ( AT,  A0,
         /**/ /**/
               A1,
          AB,  A2 );

        LockedRepartitionDown
        ( BT,  B0,
         /**/ /**/
               B1,
          BB,  B2 );

        A1_STAR_MC.AlignWith( C );
        B1_STAR_MR.AlignWith( C );
        //--------------------------------------------------------------------//
        A1_STAR_MC = A1; // A1[*,MC] <- A1[MC,MR]
        B1_STAR_MR = B1; // B1[*,MR] <- B1[MC,MR]

        // C[MC,MR] += alpha (A1[*,MC])^T B1[*,MR]
        //           = alpha (A1^T)[MC,*] B1[*,MR]
        internal::LocalGemm
        ( orientationOfA, NORMAL, alpha, A1_STAR_MC, B1_STAR_MR, (T)1, C );
        //--------------------------------------------------------------------//
        A1_STAR_MC.FreeAlignments();
        B1_STAR_MR.FreeAlignments();

        SlideLockedPartitionDown
        ( AT,  A0,
               A1,
         /**/ /**/
          AB,  A2 );

        SlideLockedPartitionDown
        ( BT,  B0,
               B1,
         /**/ /**/
          BB,  B2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #18
0
inline void
internal::GemmTNA
( Orientation orientationOfA,
  T alpha, const DistMatrix<T,MC,MR>& A,
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::GemmTNA");    
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error
        ("{A,B,C} must be distributed over the same grid");
    if( orientationOfA == NORMAL )
        throw std::logic_error("GemmTNA assumes A is (Conjugate)Transposed");
    if( A.Width()  != C.Height() ||
        B.Width()  != C.Width()  ||
        A.Height() != B.Height()   )
    {
        std::ostringstream msg;
        msg << "Nonconformal GemmTNA: \n"
            << "  A ~ " << A.Height() << " x " << A.Width() << "\n"
            << "  B ~ " << B.Height() << " x " << B.Width() << "\n"
            << "  C ~ " << C.Height() << " x " << C.Width() << "\n";
        throw std::logic_error( msg.str().c_str() );
    }
#endif
    const Grid& g = A.Grid();

    // Matrix views
    DistMatrix<T,MC,MR> BL(g), BR(g),
                        B0(g), B1(g), B2(g);

    DistMatrix<T,MC,MR> CL(g), CR(g),
                        C0(g), C1(g), C2(g);

    // Temporary distributions
    DistMatrix<T,MC,STAR> B1_MC_STAR(g);
    DistMatrix<T,MR,STAR> D1_MR_STAR(g);
    DistMatrix<T,MR,MC  > D1_MR_MC(g);
    DistMatrix<T,MC,MR  > D1(g);

    // Start the algorithm
    Scal( beta, C );
    LockedPartitionRight( B, BL, BR, 0 );
    PartitionRight( C, CL, CR, 0 );
    while( BR.Width() > 0 )
    {
        LockedRepartitionRight
        ( BL, /**/     BR,
          B0, /**/ B1, B2 );
 
        RepartitionRight
        ( CL, /**/     CR,
          C0, /**/ C1, C2 );

        B1_MC_STAR.AlignWith( A );
        D1_MR_STAR.AlignWith( A );
        D1_MR_STAR.ResizeTo( C1.Height(), C1.Width() );
        D1.AlignWith( C1 );
        //--------------------------------------------------------------------//
        B1_MC_STAR = B1; // B1[MC,*] <- B1[MC,MR]

        // D1[MR,*] := alpha (A1[MC,MR])^T B1[MC,*]
        //           = alpha (A1^T)[MR,MC] B1[MC,*]
        internal::LocalGemm
        ( orientationOfA, NORMAL, alpha, A, B1_MC_STAR, (T)0, D1_MR_STAR );

        // C1[MC,MR] += scattered & transposed D1[MR,*] summed over grid cols
        D1_MR_MC.SumScatterFrom( D1_MR_STAR );
        D1 = D1_MR_MC; 
        Axpy( (T)1, D1, C1 );
        //--------------------------------------------------------------------//
        B1_MC_STAR.FreeAlignments();
        D1_MR_STAR.FreeAlignments();
        D1.FreeAlignments();

        SlideLockedPartitionRight
        ( BL,     /**/ BR,
          B0, B1, /**/ B2 );

        SlidePartitionRight
        ( CL,     /**/ CR,
          C0, C1, /**/ C2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #19
0
void __fastcall Tunnel::MakeKeyFrames( char *nom, short nseg, short condition )
{
    short i, k;
    GLfloat tmp[3];
    GLfloat dir[10][3];

    MakeDir(nom, nseg, dir);

    ///////////////////////
    // Position KeyFrames
    ///////////////////////

    // 1st
    PosKey[0][0] = PosKey[0][1] = PosKey[0][2] = 0;
    Affect(PosKeyDir[0], dir[1]);
    PosKeyTime[0] = 0;

    // 2st
    Scal(PosKey[1], LSEG, dir[1]);
    Affect(PosKeyDir[1], dir[1]);
    PosKeyTime[1] = (double) LSEG / SPEED;

    for(k=2, i=2 ; i<=nseg ; i++)
    {
      // k-ieme
      Add(tmp, dir[i-1], dir[i]);
      Scal(tmp, RSEG, tmp);
      Add(PosKey[k], PosKey[k-1], tmp);
      Affect(PosKeyDir[k], dir[i]);
      PosKeyTime[k] = PosKeyTime[k-1] + (double) M_PI_2 * RSEG / SPEED;
      k++;

      // k-ieme (+1)
      Scal(tmp, LSEG, dir[i]);
      Add(PosKey[k], PosKey[k-1], tmp);
      Affect(PosKeyDir[k], dir[i]);
      PosKeyTime[k] = PosKeyTime[k-1] + (double) LSEG / SPEED;
      k++;
    }
    nPosKey = k-1;
    LastPosKey = 0;
    NextPosKey = 1;


    ////////////////////////////////////////////////
    // Rotation KeyFrames, fonction des conditions
    ////////////////////////////////////////////////

    if(condition == 1)
    {
      // 1st
      Affect(RotKeyDir[0], dir[1]);
      RotKeyUp[0][0] = RotKeyUp[0][2] = 0; RotKeyUp[0][1] = 1;
      RotKeyTime[0] = PosKeyTime[0];

      for(k=1, i=1 ; i<nseg ; )
      {
        // k-ieme
        Affect(RotKeyDir[k], dir[i]);
        Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
        RotKeyTime[k] = PosKeyTime[k] - (double) ANTICIPATION/SPEED;
        k++; i++;

        // k-ieme +1
        Affect(RotKeyDir[k], dir[i]);
        Cross(tmp, RotKeyDir[k-1], RotKeyDir[k]);
        if(CompareAbs(tmp, RotKeyUp[k-1]))         // Si rotation autour de RotKeyUp
          Affect(RotKeyUp[k], RotKeyUp[k-1]);
        else                                    // Sinon applique la rotation à RotKeyUp
          Cross(RotKeyUp[k], tmp, RotKeyUp[k-1]);

        RotKeyTime[k] = PosKeyTime[k];
        k++;
      }
      // dernier
      Affect(RotKeyDir[k], dir[i]);
      Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
      RotKeyTime[k] = PosKeyTime[k];

      nRotKey = k;
      LastRotKey = 0;
      NextRotKey = 1;
    }

    else if(condition == 2)
    {
      // 1st
      Affect(RotKeyDir[0], dir[1]);
      RotKeyUp[0][0] = RotKeyUp[0][2] = 0; RotKeyUp[0][1] = 1;
      RotKeyTime[0] = PosKeyTime[0];

      for(k=1, i=1 ; i<nseg ; )
      {
        // k-ieme
        Affect(RotKeyDir[k], dir[i]);
        Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
        RotKeyTime[k] = PosKeyTime[k] - (double) ANTICIPATION/SPEED;
        k++; i++;

        // k-ieme +1
        Affect(RotKeyDir[k], dir[i]);
        Cross(tmp, RotKeyDir[k-1], RotKeyDir[k]);
        if(CompareAbs(tmp, RotKeyUp[k-1]))         // Si rotation autour de RotKeyUp
          Affect(RotKeyUp[k], RotKeyUp[0]);
        else                                       // Sinon applique la rotation à RotKeyUp
          Cross(RotKeyUp[k], tmp, RotKeyUp[k-1]);

        RotKeyTime[k] = PosKeyTime[k];
        k++;
      }
      // dernier
      Affect(RotKeyDir[k], dir[i]);
      Affect(RotKeyUp[k], RotKeyUp[k-1]);    // Meme que précédement
      RotKeyTime[k] = PosKeyTime[k];

      nRotKey = k;
      LastRotKey = 0;
      NextRotKey = 1;
    }

    else if(condition == 3)
    {
      // 1st
      Affect(RotKeyDir[0], dir[1]);
      RotKeyUp[0][0] = RotKeyUp[0][2] = 0; RotKeyUp[0][1] = 1;
      RotKeyTime[0] = PosKeyTime[0];

      for(k=1, i=1 ; i<nseg ; )
      {
        // k-ieme
        Affect(RotKeyDir[k], RotKeyDir[k-1]);
        Affect(RotKeyUp[k], RotKeyUp[0]);    // Meme que précédement
        RotKeyTime[k] = PosKeyTime[k] - (double) ANTICIPATION/SPEED;
        k++; i++;

        // k-ieme +1
        if(dir[i][1] == 1 || dir[i][1] == -1)   // si segment vertical
        {
          if(i+1 <= nseg)
            Affect(RotKeyDir[k], dir[i+1]);
          else
            Affect(RotKeyDir[k], RotKeyDir[k-1]);
        }
        else
          Affect(RotKeyDir[k], dir[i]);

        Affect(RotKeyUp[k], RotKeyUp[0]);
        RotKeyTime[k] = PosKeyTime[k];
        k++;
      }
      // dernier
      if(dir[i][1] == 1 || dir[i][1] == -1)   // si segment vertical
        Affect(RotKeyDir[k], RotKeyDir[k-1]);
      else
        Affect(RotKeyDir[k], dir[i]);
      Affect(RotKeyUp[k], RotKeyUp[0]);    // Meme que précédement
      RotKeyTime[k] = PosKeyTime[k];

      nRotKey = k;
      LastRotKey = 0;
      NextRotKey = 1;
    }
}
Example #20
0
//////////////////////////////////
// Camera's position calculation
//////////////////////////////////
void __fastcall Tunnel::CameraPosition( GLfloat t )
{
    GLfloat N[3];
    GLfloat tmp[3], tmp2[3];
    double r, teta;

    //////////////////
    // Position keys
    //////////////////

    if(t >= PosKeyTime[NextPosKey])
    {
      if(NextPosKey == nPosKey)       // fin d'animation : quite
        return(false);
      else
      {
        LastPosKey++;
        NextPosKey++;
      }
    }

    if(Compare(PosKeyDir[LastPosKey], PosKeyDir[NextPosKey]))
    {
      // Segment de droite
      r = (t - PosKeyTime[LastPosKey])/(PosKeyTime[NextPosKey] - PosKeyTime[LastPosKey]);
      Scal(tmp, (GLfloat) LSEG*r, PosKeyDir[LastPosKey]);
      Add(View, tmp, PosKey[LastPosKey]);
    }
    else
    {
      // Arc de cercle
      teta = M_PI_2 * (t - PosKeyTime[LastPosKey])/(PosKeyTime[NextPosKey] - PosKeyTime[LastPosKey]);

      Scal(tmp, (GLfloat) RSEG*sin(teta), PosKeyDir[LastPosKey]);
      Scal(tmp2, (GLfloat) -RSEG*cos(teta), PosKeyDir[NextPosKey]);
      Add(View, tmp, tmp2);
      Scal(tmp, (GLfloat) RSEG, PosKeyDir[NextPosKey]);
      Add(View, View, tmp);
      Add(View, View, PosKey[LastPosKey]);
    }

    //////////////////
    // Rotation keys
    //////////////////

    if(t >= RotKeyTime[NextRotKey])
    {
      if(NextRotKey == nRotKey)       // fin d'animation : quite
        return(false);
      else
      {
        LastRotKey++;
        NextRotKey++;
      }

      // Initialisations de keyframe au cas ou pas de rotation envisagée
      Affect(ViewDir, RotKeyDir[LastRotKey]);
      Affect(ViewUp, RotKeyUp[LastRotKey]);
    }

    r = (t - RotKeyTime[LastRotKey])/(RotKeyTime[NextRotKey] - RotKeyTime[LastRotKey]);

    if(! Compare(RotKeyUp[LastRotKey], RotKeyUp[NextRotKey]))
      Interpolate(ViewUp, r, RotKeyUp[LastRotKey], RotKeyUp[NextRotKey]);

    if(! Compare(RotKeyDir[LastRotKey], RotKeyDir[NextRotKey]))
      Interpolate(ViewDir, r, RotKeyDir[LastRotKey], RotKeyDir[NextRotKey]);

#ifdef FPS_DEBUG
    frames++;
    if(frames >= 10)
    {
      char str[40];
      sprintf(str, "Navigation 3D (%.2ffps)", 10000/(t-oldt));
      fprintf(fdebug, "\n%.2ffps", 10000/(t-oldt));
//      SetWindowText(GLwin.hWnd, str);
      oldt = t;
      frames = 0;
    }
#endif

    // Calcule Ref à partir de viewdir
    Add(Ref, View, ViewDir);

    return(true);
}
Example #21
0
inline void
internal::TrmmLUNC
( UnitOrNonUnit diag,
  T alpha, const DistMatrix<T,MC,MR>& U,
                 DistMatrix<T,MC,MR>& X )
{
#ifndef RELEASE
    PushCallStack("internal::TrmmLUNC");
    if( U.Grid() != X.Grid() )
        throw std::logic_error
        ("U and X must be distributed over the same grid");
    if( U.Height() != U.Width() || U.Width() != X.Height() )
    {
        std::ostringstream msg;
        msg << "Nonconformal TrmmLUN: \n"
            << "  U ~ " << U.Height() << " x " << U.Width() << "\n"
            << "  X ~ " << X.Height() << " x " << X.Width() << "\n";
        throw std::logic_error( msg.str().c_str() );
    }
#endif
    const Grid& g = U.Grid();

    // Matrix views
    DistMatrix<T,MC,MR> 
        UTL(g), UTR(g),  U00(g), U01(g), U02(g),
        UBL(g), UBR(g),  U10(g), U11(g), U12(g),
                         U20(g), U21(g), U22(g);

    DistMatrix<T,MC,MR> XT(g),  X0(g),
                        XB(g),  X1(g),
                                X2(g);

    // Temporary distributions
    DistMatrix<T,STAR,STAR> U11_STAR_STAR(g);
    DistMatrix<T,STAR,MC  > U12_STAR_MC(g);
    DistMatrix<T,STAR,VR  > X1_STAR_VR(g);
    DistMatrix<T,MR,  STAR> D1Trans_MR_STAR(g);
    DistMatrix<T,MR,  MC  > D1Trans_MR_MC(g);
    DistMatrix<T,MC,  MR  > D1(g);

    // Start the algorithm
    Scal( alpha, X );
    LockedPartitionDownDiagonal
    ( U, UTL, UTR,
         UBL, UBR, 0 );
    PartitionDown
    ( X, XT,
         XB, 0 );
    while( XB.Height() > 0 )
    {
        LockedRepartitionDownDiagonal
        ( UTL, /**/ UTR,   U00, /**/ U01, U02,
         /*************/  /******************/
               /**/        U10, /**/ U11, U12,
          UBL, /**/ UBR,   U20, /**/ U21, U22 );

        RepartitionDown
        ( XT,  X0,
         /**/ /**/
               X1,
          XB,  X2 );

        U12_STAR_MC.AlignWith( X2 );
        D1Trans_MR_STAR.AlignWith( X1 );
        D1Trans_MR_MC.AlignWith( X1 );
        D1.AlignWith( X1 );
        D1Trans_MR_STAR.ResizeTo( X1.Width(), X1.Height() );
        D1.ResizeTo( X1.Height(), X1.Width() );
        //--------------------------------------------------------------------//
        X1_STAR_VR = X1;
        U11_STAR_STAR = U11;
        internal::LocalTrmm
        ( LEFT, UPPER, NORMAL, diag, (T)1, U11_STAR_STAR, X1_STAR_VR );
        X1 = X1_STAR_VR;
 
        U12_STAR_MC = U12;
        internal::LocalGemm
        ( TRANSPOSE, TRANSPOSE, (T)1, X2, U12_STAR_MC, (T)0, D1Trans_MR_STAR );
        D1Trans_MR_MC.SumScatterFrom( D1Trans_MR_STAR );
        Transpose( D1Trans_MR_MC.LocalMatrix(), D1.LocalMatrix() );
        Axpy( (T)1, D1, X1 );
       //--------------------------------------------------------------------//
        D1.FreeAlignments();
        D1Trans_MR_MC.FreeAlignments();
        D1Trans_MR_STAR.FreeAlignments();
        U12_STAR_MC.FreeAlignments();

        SlideLockedPartitionDownDiagonal
        ( UTL, /**/ UTR,  U00, U01, /**/ U02,
               /**/       U10, U11, /**/ U12,
         /*************/ /******************/
          UBL, /**/ UBR,  U20, U21, /**/ U22 );

        SlidePartitionDown
        ( XT,  X0,
               X1,
         /**/ /**/
          XB,  X2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #22
0
inline void
internal::SymmRUC
( T alpha, const DistMatrix<T,MC,MR>& A,
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::SymmRUC");
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error("{A,B,C} must be distributed on the same grid");
#endif
    const Grid& g = A.Grid();

    // Matrix views
    DistMatrix<T,MC,MR> 
        ATL(g), ATR(g),  A00(g), A01(g), A02(g),  AColPan(g),
        ABL(g), ABR(g),  A10(g), A11(g), A12(g),  ARowPan(g),
                         A20(g), A21(g), A22(g);

    DistMatrix<T,MC,MR> BL(g), BR(g),
                        B0(g), B1(g), B2(g);

    DistMatrix<T,MC,MR> CL(g), CR(g),
                        C0(g), C1(g), C2(g),
                        CLeft(g), CRight(g);

    // Temporary distributions
    DistMatrix<T,MC,  STAR> B1_MC_STAR(g);
    DistMatrix<T,VR,  STAR> AColPan_VR_STAR(g);
    DistMatrix<T,STAR,MR  > AColPanTrans_STAR_MR(g);
    DistMatrix<T,MR,  STAR> ARowPanTrans_MR_STAR(g);

    // Start the algorithm
    Scal( beta, C );
    LockedPartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 );
    LockedPartitionRight( B, BL, BR, 0 );
    PartitionRight( C, CL, CR, 0 );
    while( CR.Width() > 0 )
    {
        LockedRepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ A01, A02,
         /*************/ /******************/
               /**/       A10, /**/ A11, A12,
          ABL, /**/ ABR,  A20, /**/ A21, A22 );

        LockedRepartitionRight
        ( BL, /**/ BR,
          B0, /**/ B1, B2 );

        RepartitionRight
        ( CL, /**/ CR,
          C0, /**/ C1, C2 );

        ARowPan.LockedView1x2( A11, A12 );

        AColPan.LockedView2x1
        ( A01,
          A11 );

        CLeft.View1x2( C0, C1 );

        CRight.View1x2( C1, C2 );

        B1_MC_STAR.AlignWith( C );
        AColPan_VR_STAR.AlignWith( CLeft );
        AColPanTrans_STAR_MR.AlignWith( CLeft );
        ARowPanTrans_MR_STAR.AlignWith( CRight );
        //--------------------------------------------------------------------//
        B1_MC_STAR = B1;

        AColPan_VR_STAR = AColPan;
        AColPanTrans_STAR_MR.TransposeFrom( AColPan_VR_STAR );
        ARowPanTrans_MR_STAR.TransposeFrom( ARowPan );
        MakeTrapezoidal( LEFT,  LOWER,  0, ARowPanTrans_MR_STAR );
        MakeTrapezoidal( RIGHT, LOWER, -1, AColPanTrans_STAR_MR );

        internal::LocalGemm
        ( NORMAL, TRANSPOSE, 
          alpha, B1_MC_STAR, ARowPanTrans_MR_STAR, (T)1, CRight );

        internal::LocalGemm
        ( NORMAL, NORMAL,
          alpha, B1_MC_STAR, AColPanTrans_STAR_MR, (T)1, CLeft );
        //--------------------------------------------------------------------//
        B1_MC_STAR.FreeAlignments();
        AColPan_VR_STAR.FreeAlignments();
        AColPanTrans_STAR_MR.FreeAlignments();
        ARowPanTrans_MR_STAR.FreeAlignments();

        SlideLockedPartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, A01, /**/ A02,
               /**/       A10, A11, /**/ A12,
         /*************/ /******************/
          ABL, /**/ ABR,  A20, A21, /**/ A22 );

        SlideLockedPartitionRight
        ( BL,     /**/ BR,
          B0, B1, /**/ B2 );

        SlidePartitionRight
        ( CL,     /**/ CR,
          C0, C1, /**/ C2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #23
0
inline void
internal::HemmLLA
( T alpha, const DistMatrix<T,MC,MR>& A, 
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::HemmLLA");
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error
        ("{A,B,C} must be distributed over the same grid");
#endif
    const Grid& g = A.Grid();

    DistMatrix<T,MC,MR> 
        BL(g), BR(g),
        B0(g), B1(g), B2(g);

    DistMatrix<T,MC,MR>
        CL(g), CR(g),
        C0(g), C1(g), C2(g);

    DistMatrix<T,MC,STAR> B1_MC_STAR(g);
    DistMatrix<T,VR,STAR> B1_VR_STAR(g);
    DistMatrix<T,STAR,MR> B1Adj_STAR_MR(g);
    DistMatrix<T,MC,MR  > Z1(g);
    DistMatrix<T,MC,STAR> Z1_MC_STAR(g);
    DistMatrix<T,MR,STAR> Z1_MR_STAR(g);
    DistMatrix<T,MR,MC  > Z1_MR_MC(g);

    Scal( beta, C );
    LockedPartitionRight
    ( B, BL, BR, 0 );
    PartitionRight
    ( C, CL, CR, 0 );
    while( CL.Width() < C.Width() )
    {
        LockedRepartitionRight 
        ( BL, /**/ BR,
          B0, /**/ B1, B2 );

        RepartitionRight
        ( CL, /**/ CR,
          C0, /**/ C1, C2 );

        B1_MC_STAR.AlignWith( A );
        B1_VR_STAR.AlignWith( A );
        B1Adj_STAR_MR.AlignWith( A );
        Z1_MC_STAR.AlignWith( A );
        Z1_MR_STAR.AlignWith( A );
        Z1.AlignWith( C1 );
        Z1_MC_STAR.ResizeTo( C1.Height(), C1.Width() );
        Z1_MR_STAR.ResizeTo( C1.Height(), C1.Width() );
        //--------------------------------------------------------------------//
        B1_MC_STAR = B1;
        B1_VR_STAR = B1_MC_STAR;
        B1Adj_STAR_MR.AdjointFrom( B1_VR_STAR );
        Zero( Z1_MC_STAR );
        Zero( Z1_MR_STAR );
        internal::LocalSymmetricAccumulateLL
        ( ADJOINT, 
          alpha, A, B1_MC_STAR, B1Adj_STAR_MR, Z1_MC_STAR, Z1_MR_STAR );

        Z1_MR_MC.SumScatterFrom( Z1_MR_STAR );
        Z1 = Z1_MR_MC;
        Z1.SumScatterUpdate( (T)1, Z1_MC_STAR );
        Axpy( (T)1, Z1, C1 );
        //--------------------------------------------------------------------//
        B1_MC_STAR.FreeAlignments();
        B1_VR_STAR.FreeAlignments();
        B1Adj_STAR_MR.FreeAlignments();
        Z1_MC_STAR.FreeAlignments();
        Z1_MR_STAR.FreeAlignments();
        Z1.FreeAlignments();

        SlideLockedPartitionRight
        ( BL,     /**/ BR,
          B0, B1, /**/ B2 );

        SlidePartitionRight
        ( CL,     /**/ CR,
          C0, C1, /**/ C2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
Example #24
0
inline void
internal::PanelLU
( DistMatrix<F,  STAR,STAR>& A, 
  DistMatrix<F,  MC,  STAR>& B, 
  DistMatrix<int,STAR,STAR>& p, 
  int pivotOffset )
{
#ifndef RELEASE
    PushCallStack("internal::PanelLU");
    if( A.Grid() != p.Grid() || p.Grid() != B.Grid() )
        throw std::logic_error
        ("Matrices must be distributed over the same grid");
    if( A.Width() != B.Width() )
        throw std::logic_error("A and B must be the same width");
    if( A.Height() != p.Height() || p.Width() != 1 )
        throw std::logic_error("p must be a vector that conforms with A");
#endif
    const Grid& g = A.Grid();
    const int r = g.Height();
    const int colShift = B.ColShift();
    const int colAlignment = B.ColAlignment();

    // Matrix views
    DistMatrix<F,STAR,STAR> 
        ATL(g), ATR(g),  A00(g), a01(g),     A02(g),  
        ABL(g), ABR(g),  a10(g), alpha11(g), a12(g),  
                         A20(g), a21(g),     A22(g);

    DistMatrix<F,MC,STAR>
        BL(g), BR(g),
        B0(g), b1(g), B2(g);

    DistMatrix<int,STAR,STAR>
        pT(g),  p0(g),
        pB(g),  psi1(g),
                p2(g);

    const int width = A.Width();
    const int numBytes = (width+1)*sizeof(F)+sizeof(int);
    std::vector<byte> sendData(numBytes);
    std::vector<byte> recvData(numBytes);

    // Extract pointers to send and recv data
    F* sendBufFloat = (F*) &sendData[0];
    F* recvBufFloat = (F*) &recvData[0];
    int* sendBufInt = (int*) &sendData[(width+1)*sizeof(F)];
    int* recvBufInt = (int*) &recvData[(width+1)*sizeof(F)];

    // Start the algorithm
    PushBlocksizeStack( 1 );
    PartitionDownDiagonal
    ( A, ATL, ATR,
         ABL, ABR, 0 );
    PartitionRight( B, BL, BR, 0 );
    PartitionDown
    ( p, pT,
         pB, 0 );
    while( ATL.Height() < A.Height() )
    {
        RepartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, /**/ a01,     A02,
         /*************/ /**********************/
               /**/       a10, /**/ alpha11, a12,
          ABL, /**/ ABR,  A20, /**/ a21,     A22 );

        RepartitionRight
        ( BL, /**/ BR,  
          B0, /**/ b1, B2 );

        RepartitionDown
        ( pT,  p0,
         /**/ /****/
               psi1,
          pB,  p2 );

        //--------------------------------------------------------------------//
        
        // Store the index/value of the pivot candidate in A
        F pivotValue = alpha11.GetLocalEntry(0,0);
        int pivotIndex = a01.Height();
        for( int i=0; i<a21.Height(); ++i )
        {
            F value = a21.GetLocalEntry(i,0);
            if( FastAbs(value) > FastAbs(pivotValue) )
            {
                pivotValue = value;
                pivotIndex = a01.Height() + i + 1;
            }
        }

        // Update the pivot candidate to include local data from B
        for( int i=0; i<B.LocalHeight(); ++i )
        {
            F value = b1.GetLocalEntry(i,0);
            if( FastAbs(value) > FastAbs(pivotValue) )
            {
                pivotValue = value;
                pivotIndex = A.Height() + colShift + i*r;
            }
        }

        // Fill the send buffer with:
        // [ pivotValue | pivotRow | pivotIndex ]
        if( pivotIndex < A.Height() )
        {
            sendBufFloat[0] = A.GetLocalEntry(pivotIndex,a10.Width());

            const int ALDim = A.LocalLDim();
            const F* ABuffer = A.LocalBuffer(pivotIndex,0);
            for( int j=0; j<width; ++j )
                sendBufFloat[j+1] = ABuffer[j*ALDim];
        }
        else
        {
            const int localIndex = ((pivotIndex-A.Height())-colShift)/r;
            sendBufFloat[0] = b1.GetLocalEntry(localIndex,0);

            const int BLDim = B.LocalLDim();
            const F* BBuffer = B.LocalBuffer(localIndex,0);
            for( int j=0; j<width; ++j )
                sendBufFloat[j+1] = BBuffer[j*BLDim];
        }
        *sendBufInt = pivotIndex;

        // Communicate to establish the pivot information
        mpi::AllReduce
        ( &sendData[0], &recvData[0], numBytes, PivotOp<F>(), g.ColComm() );

        // Update the pivot vector
        const int maxIndex = *recvBufInt;
        p.SetLocalEntry(a01.Height(),0,maxIndex+pivotOffset);

        // Copy the current row into the pivot row
        if( maxIndex < A.Height() )
        {
            const int ALDim = A.LocalLDim();
            F* ASetBuffer = A.LocalBuffer(maxIndex,0);
            const F* AGetBuffer = A.LocalBuffer(A00.Height(),0);
            for( int j=0; j<width; ++j )
                ASetBuffer[j*ALDim] = AGetBuffer[j*ALDim];
        }
        else
        {
            const int ownerRank = (colAlignment+(maxIndex-A.Height())) % r;
            if( g.Row() == ownerRank )
            {
                const int localIndex = ((maxIndex-A.Height())-colShift) / r;

                const int ALDim = A.LocalLDim();
                const int BLDim = B.LocalLDim();
                F* BBuffer = B.LocalBuffer(localIndex,0);
                const F* ABuffer = A.LocalBuffer(A00.Height(),0);
                for( int j=0; j<width; ++j )
                    BBuffer[j*BLDim] = ABuffer[j*ALDim];
            }
        }

        // Copy the pivot row into the current row
        {
            F* ABuffer = A.LocalBuffer(A00.Height(),0);
            const int ALDim = A.LocalLDim();
            for( int j=0; j<width; ++j )
                ABuffer[j*ALDim] = recvBufFloat[j+1];
        }

        // Now we can perform the update of the current panel
        F alpha = alpha11.GetLocalEntry(0,0);
        if( alpha == (F)0 )
            throw SingularMatrixException();
        F alpha11Inv = ((F)1) / alpha;
        Scal( alpha11Inv, a21.LocalMatrix() );
        Scal( alpha11Inv, b1.LocalMatrix()  );
        Geru( (F)-1, a21.LocalMatrix(), a12.LocalMatrix(), A22.LocalMatrix() );
        Geru( (F)-1, b1.LocalMatrix(), a12.LocalMatrix(), B2.LocalMatrix() );
        //--------------------------------------------------------------------//

        SlidePartitionDownDiagonal
        ( ATL, /**/ ATR,  A00, a01,     /**/ A02,
               /**/       a10, alpha11, /**/ a12,
         /*************/ /**********************/
          ABL, /**/ ABR,  A20, a21,     /**/ A22 );

        SlidePartitionRight
        ( BL,     /**/ BR,  
          B0, b1, /**/ B2 );

        SlidePartitionDown
        ( pT,  p0,
               psi1,
         /**/ /****/
          pB,  p2 );
    }
    PopBlocksizeStack();

#ifndef RELEASE
    PopCallStack();
#endif
}
Example #25
0
inline void
internal::SymmRUA
( T alpha, const DistMatrix<T,MC,MR>& A,
           const DistMatrix<T,MC,MR>& B,
  T beta,        DistMatrix<T,MC,MR>& C )
{
#ifndef RELEASE
    PushCallStack("internal::SymmRUA");
    if( A.Grid() != B.Grid() || B.Grid() != C.Grid() )
        throw std::logic_error
        ("{A,B,C} must be distributed over the same grid");
#endif
    const Grid& g = A.Grid();

    DistMatrix<T,MC,MR>
        BT(g),  B0(g),
        BB(g),  B1(g),
                B2(g);

    DistMatrix<T,MC,MR>
        CT(g),  C0(g),
        CB(g),  C1(g),
                C2(g);

    DistMatrix<T,MR,  STAR> B1Trans_MR_STAR(g);
    DistMatrix<T,VC,  STAR> B1Trans_VC_STAR(g);
    DistMatrix<T,STAR,MC  > B1_STAR_MC(g);
    DistMatrix<T,MC,  STAR> Z1Trans_MC_STAR(g);
    DistMatrix<T,MR,  STAR> Z1Trans_MR_STAR(g);
    DistMatrix<T,MC,  MR  > Z1Trans(g);
    DistMatrix<T,MR,  MC  > Z1Trans_MR_MC(g);

    Matrix<T> Z1Local;

    Scal( beta, C );
    LockedPartitionDown
    ( B, BT,
         BB, 0 );
    PartitionDown
    ( C, CT,
         CB, 0 );
    while( CT.Height() < C.Height() )
    {
        LockedRepartitionDown
        ( BT,  B0, 
         /**/ /**/
               B1,
          BB,  B2 );

        RepartitionDown
        ( CT,  C0,
         /**/ /**/
               C1,
          CB,  C2 );

        B1Trans_MR_STAR.AlignWith( A );
        B1Trans_VC_STAR.AlignWith( A );
        B1_STAR_MC.AlignWith( A );
        Z1Trans_MC_STAR.AlignWith( A );
        Z1Trans_MR_STAR.AlignWith( A );
        Z1Trans_MR_MC.AlignWith( C1 );
        Z1Trans_MC_STAR.ResizeTo( C1.Width(), C1.Height() );
        Z1Trans_MR_STAR.ResizeTo( C1.Width(), C1.Height() );
        //--------------------------------------------------------------------//
        B1Trans_MR_STAR.TransposeFrom( B1 );
        B1Trans_VC_STAR = B1Trans_MR_STAR;
        B1_STAR_MC.TransposeFrom( B1Trans_VC_STAR );
        Zero( Z1Trans_MC_STAR );
        Zero( Z1Trans_MR_STAR );
        internal::LocalSymmetricAccumulateRU
        ( TRANSPOSE, alpha, A, B1_STAR_MC, B1Trans_MR_STAR, 
          Z1Trans_MC_STAR, Z1Trans_MR_STAR );

        Z1Trans.SumScatterFrom( Z1Trans_MC_STAR );
        Z1Trans_MR_MC = Z1Trans;
        Z1Trans_MR_MC.SumScatterUpdate( (T)1, Z1Trans_MR_STAR );
        Transpose( Z1Trans_MR_MC.LockedLocalMatrix(), Z1Local );
        Axpy( (T)1, Z1Local, C1.LocalMatrix() );
        //--------------------------------------------------------------------//
        B1Trans_MR_STAR.FreeAlignments();
        B1Trans_VC_STAR.FreeAlignments();
        B1_STAR_MC.FreeAlignments();
        Z1Trans_MC_STAR.FreeAlignments();
        Z1Trans_MR_STAR.FreeAlignments();
        Z1Trans_MR_MC.FreeAlignments();

        SlideLockedPartitionDown
        ( BT,  B0,
               B1,
         /**/ /**/
          BB,  B2 );

        SlidePartitionDown
        ( CT,  C0,
               C1,
         /**/ /**/
          CB,  C2 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}