1 /*
2 Copyright (c) 2009-2014, Jack Poulson
3 All rights reserved.
4
5 This file is part of Elemental and is under the BSD 2-Clause License,
6 which can be found in the LICENSE file in the root directory, or at
7 http://opensource.org/licenses/BSD-2-Clause
8 */
9 #pragma once
10 #ifndef ELEM_MINIJ_HPP
11 #define ELEM_MINIJ_HPP
12
13 namespace elem {
14
15 template<typename T>
16 inline void
MinIJ(Matrix<T> & M,Int n)17 MinIJ( Matrix<T>& M, Int n )
18 {
19 DEBUG_ONLY(CallStackEntry cse("MinIJ"))
20 M.Resize( n, n );
21 for( Int j=0; j<n; ++j )
22 for( Int i=0; i<n; ++i )
23 M.Set( i, j, std::min(i+1,j+1) );
24 }
25
26 template<typename T,Dist U,Dist V>
27 inline void
MinIJ(DistMatrix<T,U,V> & M,Int n)28 MinIJ( DistMatrix<T,U,V>& M, Int n )
29 {
30 DEBUG_ONLY(CallStackEntry cse("MinIJ"))
31 M.Resize( n, n );
32 const Int localHeight = M.LocalHeight();
33 const Int localWidth = M.LocalWidth();
34 for( Int jLoc=0; jLoc<localWidth; ++jLoc )
35 {
36 const Int j = M.GlobalCol(jLoc);
37 for( Int iLoc=0; iLoc<localHeight; ++iLoc )
38 {
39 const Int i = M.GlobalRow(iLoc);
40 M.SetLocal( iLoc, jLoc, std::min(i+1,j+1) );
41 }
42 }
43 }
44
45 template<typename T,Dist U,Dist V>
46 inline void
MinIJ(BlockDistMatrix<T,U,V> & M,Int n)47 MinIJ( BlockDistMatrix<T,U,V>& M, Int n )
48 {
49 DEBUG_ONLY(CallStackEntry cse("MinIJ"))
50 M.Resize( n, n );
51 const Int localHeight = M.LocalHeight();
52 const Int localWidth = M.LocalWidth();
53 for( Int jLoc=0; jLoc<localWidth; ++jLoc )
54 {
55 const Int j = M.GlobalCol(jLoc);
56 for( Int iLoc=0; iLoc<localHeight; ++iLoc )
57 {
58 const Int i = M.GlobalRow(iLoc);
59 M.SetLocal( iLoc, jLoc, std::min(i+1,j+1) );
60 }
61 }
62 }
63
64 } // namespace elem
65
66 #endif // ifndef ELEM_MINIJ_HPP
67