ScaLAPACK  2.0.2 ScaLAPACK: Scalable Linear Algebra PACKage
PB_Clcm.c File Reference
`#include "../pblas.h"`
`#include "../PBpblas.h"`
`#include "../PBtools.h"`
`#include "../PBblacs.h"`
`#include "../PBblas.h"`
Include dependency graph for PB_Clcm.c:

Go to the source code of this file.

## Functions/Subroutines

int PB_Clcm (int M, int N)

## Function/Subroutine Documentation

 int PB_Clcm ( int M, int N )

Definition at line 22 of file PB_Clcm.c.

```{
/*
*  Purpose
*  =======
*
*  PB_Clcm computes and returns the Least Common Multiple  (LCM)  of two
*  positive integers M and N. In fact, the routine computes the Greatest
*  Common Divisor (GCD) and use the property that M*N = GCD*LCM.
*
*  Arguments
*  =========
*
*  M       (input) INTEGER
*          On entry, M must be at least zero.
*
*  N       (input) INTEGER
*          On entry, N must be at least zero.
*
*  -- Written on April 1, 1998 by
*     Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
*
*  ---------------------------------------------------------------------
*/
/*
*  .. Local Scalars ..
*/
int            gcd=1, m_val, n_val, t;
/* ..
*  .. Executable Statements ..
*
*/
if( M > N ) { m_val = N; n_val = M; }
else        { m_val = M; n_val = N; }

while( m_val > 0 )
{
while( !( m_val & 1 ) )
{
/*
*  m is even
*/
m_val >>= 1;
/*
*  if n is odd, gcd( m, n ) = gcd( m / 2, n )
*/
if( !( n_val & 1 ) )
{
/*
*  otherwise gcd( m, n ) = 2 * gcd( m / 2, n / 2 )
*/
n_val >>= 1;
gcd   <<= 1;
}
}
/*
*  m is odd now. If n is odd, gcd( m, n ) = gcd( m, ( m - n ) / 2 ).
*  Otherwise, gcd( m, n ) = gcd ( m, n / 2 ).
*/
n_val -= ( n_val & 1 ) ? m_val : 0;
n_val >>= 1;
while( n_val >= m_val )
{
/*
*  If n is odd, gcd( m, n ) = gcd( m, ( m - n ) / 2 ).
*  Otherwise, gcd( m, n ) = gcd ( m, n / 2 )
*/
n_val -= ( n_val & 1 ) ? m_val : 0;
n_val >>= 1;
}
/*
*  n < m, gcd( m, n ) = gcd( n, m )
*/
t     = n_val;
n_val = m_val;
m_val = t;
}
return ( ( M * N ) / ( n_val * gcd ) );
/*
*  End of PB_Clcm
*/
}
```

Here is the caller graph for this function: