Skip to content

Commit 6397f52

Browse files
Merge pull request #17 from wavefunction91/feature/lascl
Add XLASCL functions + misc functionality
2 parents 711ef36 + 810d943 commit 6397f52

35 files changed

+271
-4
lines changed

.github/workflows/cmake.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ jobs:
6464
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
6565
run: ctest -C $BUILD_TYPE
6666

67+
- name: TestFail
68+
working-directory: ${{runner.workspace}}/build
69+
if: failure()
70+
run: cat Testing/Temporary/LastTest.log
71+
6772
- name: Install
6873
working-directory: ${{runner.workspace}}/build
6974
shell: bash

include/scalapackpp/block_cyclic.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class BlockCyclicDist2D {
3434

3535
BlockCyclicDist2D( const Grid& grid, int64_t MB, int64_t NB );
3636

37+
BlockCyclicDist2D( Grid&& grid, int64_t MB, int64_t NB,
38+
int64_t ISRC, int64_t JSRC);
39+
40+
BlockCyclicDist2D( Grid&& grid, int64_t MB, int64_t NB );
3741

3842
BlockCyclicDist2D( const BlockCyclicDist2D& );
3943
BlockCyclicDist2D( BlockCyclicDist2D&& ) noexcept ;
@@ -102,6 +106,16 @@ class BlockCyclicDist2D {
102106

103107
}
104108

109+
inline std::pair<int64_t,int64_t>
110+
global_idx( int64_t i, int64_t j ) const noexcept {
111+
112+
auto l = i / mb_;
113+
auto m = j / nb_;
114+
115+
return { (l * (grid_.npr() - 1) + grid_.ipr()) * mb_ + i,
116+
(m * (grid_.npc() - 1) + grid_.ipc()) * nb_ + j };
117+
}
118+
105119

106120
inline const blacspp::Grid& grid() const { return grid_; }
107121

include/scalapackpp/lascl.hpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* This file is a part of scalapackpp (see LICENSE)
3+
*
4+
* Copyright (c) 2019-2020 David Williams-Young
5+
* All rights reserved
6+
*/
7+
#pragma once
8+
#include <scalapackpp/wrappers/lascl.hpp>
9+
#include <scalapackpp/util/type_conversions.hpp>
10+
11+
#include <scalapackpp/block_cyclic_matrix.hpp>
12+
13+
namespace scalapackpp {
14+
15+
template <typename T>
16+
detail::enable_if_scalapack_supported_t<T>
17+
plascl( MatrixType type, detail::real_t<T> CFROM,
18+
detail::real_t<T> CTO, int64_t M, int64_t N,
19+
T* A, int64_t IA, int64_t JA, const scalapack_desc& DESCA ) {
20+
21+
auto TYPE = char( type );
22+
wrappers::plascl( &TYPE, CFROM, CTO, M, N, A, IA, JA, DESCA );
23+
24+
}
25+
26+
template <typename T>
27+
detail::enable_if_scalapack_supported_t<T>
28+
plascl( MatrixType type, detail::real_t<T> ALPHA, int64_t M, int64_t N,
29+
T* A, int64_t IA, int64_t JA, const scalapack_desc& DESCA ) {
30+
31+
plascl( type, 1., ALPHA, M, N, A, IA, JA, DESCA );
32+
33+
}
34+
35+
template <typename T>
36+
detail::enable_if_scalapack_supported_t<T>
37+
plascl( MatrixType type, detail::real_t<T> CFROM,
38+
detail::real_t<T> CTO, BlockCyclicMatrix<T>& A ) {
39+
40+
plascl( type, CFROM, CTO, A.m(), A.n(), A.data(), 1, 1, A.desc() );
41+
42+
}
43+
44+
template <typename T>
45+
detail::enable_if_scalapack_supported_t<T>
46+
plascl( MatrixType type, detail::real_t<T> ALPHA, BlockCyclicMatrix<T>& A ) {
47+
48+
plascl( type, 1., ALPHA, A );
49+
50+
}
51+
52+
}

include/scalapackpp/types.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ namespace internal {
7777
Max = 'M'
7878
};
7979

80+
enum class MatrixType : char {
81+
Full = 'G',
82+
Lower = 'L',
83+
Upper = 'U',
84+
Hessenberg = 'H'
85+
};
8086

8187
using blacspp::Uplo;
8288
using blacspp::Diag;

include/scalapackpp/util/type_conversions.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,15 @@ namespace detail {
4545

4646
}
4747

48+
inline Op to_op( char c ) {
49+
switch(c) {
50+
case 'N': return Op::NoTrans;
51+
case 'T': return Op::Trans;
52+
case 'C': return Op::ConjTrans;
53+
default:
54+
throw std::runtime_error("Op Not Defined");
55+
abort();
56+
}
57+
}
4858
}
4959
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* This file is a part of scalapackpp (see LICENSE)
3+
*
4+
* Copyright (c) 2019-2020 David Williams-Young
5+
* All rights reserved
6+
*/
7+
#pragma once
8+
#include <scalapackpp/types.hpp>
9+
#include <scalapackpp/util/type_traits.hpp>
10+
11+
namespace scalapackpp {
12+
namespace wrappers {
13+
14+
template <typename T>
15+
detail::enable_if_scalapack_supported_t<T>
16+
plascl( const char* TYPE, detail::real_t<T> CFROM, detail::real_t<T> CTO,
17+
int64_t M, int64_t N, T* A, int64_t IA, int64_t JA,
18+
const scalapack_desc& DESCA );
19+
20+
21+
}
22+
}

src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if( NOT TARGET blacspp::blacspp )
88
include( FetchContent )
99
FetchContent_Declare( blacspp
1010
GIT_REPOSITORY https://github.com/wavefunction91/blacspp.git
11-
GIT_TAG b6de5b172738981ec84adcc517432c7b34c7ae60
11+
GIT_TAG f5cd6150d9b18790a17a5de667c44e300eafb3ad
1212
)
1313
FetchContent_MakeAvailable( blacspp )
1414

@@ -63,6 +63,7 @@ set( ScaLAPACKPP_SRC
6363
lanhe.cxx
6464
scal.cxx
6565
lacpy.cxx
66+
lascl.cxx
6667
)
6768

6869

src/block_cyclic.cxx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ BlockCyclicDist2D::BlockCyclicDist2D(
1818
const blacspp::Grid& grid, int64_t MB, int64_t NB
1919
) : BlockCyclicDist2D( grid, MB, NB, 0, 0 ){ }
2020

21+
BlockCyclicDist2D::BlockCyclicDist2D( blacspp::Grid&& grid,
22+
int64_t MB, int64_t NB, int64_t ISRC, int64_t JSRC
23+
) : grid_(std::move(grid)), mb_(MB), nb_(NB), isrc_(ISRC), jsrc_(JSRC){ }
24+
25+
BlockCyclicDist2D::BlockCyclicDist2D(
26+
blacspp::Grid&& grid, int64_t MB, int64_t NB
27+
) : BlockCyclicDist2D( std::move(grid), MB, NB, 0, 0 ){ }
28+
2129
BlockCyclicDist2D::BlockCyclicDist2D() = default;
2230
BlockCyclicDist2D::BlockCyclicDist2D( const BlockCyclicDist2D& ) = default;
2331
BlockCyclicDist2D::BlockCyclicDist2D( BlockCyclicDist2D&& ) noexcept = default;

src/lascl.cxx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* This file is a part of scalapackpp (see LICENSE)
3+
*
4+
* Copyright (c) 2019-2020 David Williams-Young
5+
* All rights reserved
6+
*/
7+
#include <scalapackpp/wrappers/lascl.hpp>
8+
#include <scalapackpp/util/type_conversions.hpp>
9+
10+
using scalapackpp::internal::scalapack_int;
11+
using scalapackpp::internal::dcomplex;
12+
using scalapackpp::internal::scomplex;
13+
14+
// Prototypes
15+
extern "C" {
16+
17+
void pslascl_( const char*, const float*, const float*, const scalapack_int* M,
18+
const scalapack_int* N, float* A, const scalapack_int* IA,
19+
const scalapack_int* JA, const scalapack_int* DESCA,
20+
scalapack_int* INFO );
21+
22+
void pdlascl_( const char*, const double*, const double*, const scalapack_int* M,
23+
const scalapack_int* N, double* A, const scalapack_int* IA,
24+
const scalapack_int* JA, const scalapack_int* DESCA,
25+
scalapack_int* INFO );
26+
27+
void pclascl_( const char*, const float*, const float*, const scalapack_int* M,
28+
const scalapack_int* N, scomplex* A, const scalapack_int* IA,
29+
const scalapack_int* JA, const scalapack_int* DESCA,
30+
scalapack_int* INFO );
31+
32+
void pzlascl_( const char*, const double*, const double*, const scalapack_int* M,
33+
const scalapack_int* N, dcomplex* A, const scalapack_int* IA,
34+
const scalapack_int* JA, const scalapack_int* DESCA,
35+
scalapack_int* INFO );
36+
37+
}
38+
39+
namespace scalapackpp {
40+
namespace wrappers {
41+
42+
#define plascl_impl(F, FNAME) \
43+
template <> \
44+
void plascl( const char* TYPE, detail::real_t<F> CFROM, detail::real_t<F> CTO, \
45+
int64_t M, int64_t N, F* A, int64_t IA, int64_t JA, \
46+
const scalapack_desc& DESCA) { \
47+
\
48+
auto _M = detail::to_scalapack_int( M ); \
49+
auto _N = detail::to_scalapack_int( N ); \
50+
auto _IA = detail::to_scalapack_int( IA ); \
51+
auto _JA = detail::to_scalapack_int( JA ); \
52+
\
53+
auto _DESCA = detail::to_scalapack_int( DESCA ); \
54+
scalapack_int INFO; \
55+
\
56+
FNAME( TYPE, &CFROM, &CTO, &_M, &_N, A, &_IA, &_JA, _DESCA.data(),&INFO); \
57+
}
58+
59+
plascl_impl( float, pslascl_ );
60+
plascl_impl( double, pdlascl_ );
61+
plascl_impl( scomplex, pclascl_ );
62+
plascl_impl( dcomplex, pzlascl_ );
63+
64+
}
65+
}
66+

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ add_executable( test_scalapackpp
6565
trtri.cxx
6666
norm.cxx
6767
lacpy.cxx
68+
lascl.cxx
6869
)
6970
target_link_libraries( test_scalapackpp PUBLIC ut_framework )
7071

0 commit comments

Comments
 (0)