Skip to content

Commit b17a381

Browse files
committed
Merge branch 'env-cholqr' into 'master'
Add the option to enable/disable CholQR through ChASE config See merge request SLai/ChASE!30
2 parents b98ec77 + 4eca33a commit b17a381

11 files changed

Lines changed: 114 additions & 124 deletions

File tree

ChASE-MPI/CMakeLists.txt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ cmake_minimum_required( VERSION 3.8 )
55

66
# project( ChASE-MPI LANGUAGES C CXX CUDA )
77

8-
find_package(OpenMP)
9-
if(OpenMP_FOUND)
10-
target_compile_definitions( chase_algorithm INTERFACE "HAS_OMP" )
11-
endif()
12-
138
add_library( chase_seq INTERFACE )
149
target_link_libraries(chase_seq INTERFACE chase_algorithm)
1510
target_compile_definitions(chase_seq INTERFACE NO_MPI=1 )
@@ -60,12 +55,6 @@ if(SCALAPACK_FOUND)
6055
)
6156
endif()
6257

63-
if(OpenMP_FOUND)
64-
target_link_libraries( chase_seq INTERFACE
65-
OpenMP::OpenMP_CXX
66-
)
67-
endif()
68-
6958
target_compile_options( chase_seq INTERFACE
7059
${CMAKE_C_FLAGS}
7160
${MPI_CXX_COMPILE_FLAGS}
@@ -94,16 +83,10 @@ if(SCALAPACK_FOUND)
9483
)
9584
endif()
9685

97-
target_compile_definitions( chase_mpi INTERFACE
86+
target_compile_definitions( chase_mpi INTERFACE
9887
"-DUSE_MPI"
9988
)
10089

101-
if(OpenMP_FOUND)
102-
target_link_libraries( chase_mpi INTERFACE
103-
OpenMP::OpenMP_CXX
104-
)
105-
endif()
106-
10790
include(CheckLanguage)
10891
check_language(CUDA)
10992
if(CMAKE_CUDA_COMPILER)

ChASE-MPI/chase_mpi.hpp

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
#include <random>
1717

18-
#ifdef HAS_OMP
19-
#include <omp.h>
20-
#endif
21-
2218
#include "algorithm/chase.hpp"
2319

2420
#include "blas_templates.hpp"
@@ -471,13 +467,23 @@ class ChaseMpi : public chase::Chase<T>
471467
#ifdef USE_MPI
472468
MPI_Comm_rank(MPI_COMM_WORLD, &grank);
473469
#endif
470+
int diasable = 0;
471+
472+
if(config_.DoCholQR())
473+
{
474+
diasable = 0;
475+
}else
476+
{
477+
diasable = 1;
478+
}
479+
474480
char* cholddisable;
475481
cholddisable = getenv("CHASE_DISABLE_CHOLQR");
476-
int diasable = 0;
477482
if (cholddisable)
478483
{
479484
diasable = std::atoi(cholddisable);
480485
}
486+
481487
if (diasable == 1)
482488
{
483489
#ifdef CHASE_OUTPUT
@@ -573,16 +579,7 @@ class ChaseMpi : public chase::Chase<T>
573579
#ifdef USE_NSIGHT
574580
nvtxRangePop();
575581
#endif
576-
#ifdef HAS_OMP
577-
char* omp_threads;
578-
omp_threads = getenv("OMP_NUM_THREADS");
579-
int num_threads = 1;
580-
if (omp_threads)
581-
{
582-
num_threads = std::atoi(omp_threads);
583-
}
584-
omp_set_num_threads(1);
585-
#endif
582+
586583
#ifdef USE_NSIGHT
587584
nvtxRangePushA("Lanczos: loop");
588585
#endif
@@ -643,9 +640,7 @@ class ChaseMpi : public chase::Chase<T>
643640
#ifdef USE_NSIGHT
644641
nvtxRangePop();
645642
#endif
646-
#ifdef HAS_OMP
647-
omp_set_num_threads(num_threads);
648-
#endif
643+
649644
delete[] ritzv;
650645
delete[] isuppz;
651646
delete[] d;
@@ -693,16 +688,6 @@ class ChaseMpi : public chase::Chase<T>
693688
#ifdef USE_NSIGHT
694689
nvtxRangePop();
695690
#endif
696-
#ifdef HAS_OMP
697-
char* omp_threads;
698-
omp_threads = getenv("OMP_NUM_THREADS");
699-
int num_threads = 1;
700-
if (omp_threads)
701-
{
702-
num_threads = std::atoi(omp_threads);
703-
}
704-
omp_set_num_threads(1);
705-
#endif
706691
// ENSURE that v1 has one norm
707692
#ifdef USE_NSIGHT
708693
nvtxRangePushA("Lanczos: loop");
@@ -762,9 +747,7 @@ class ChaseMpi : public chase::Chase<T>
762747
{
763748
Tau[k] = std::abs(ritzV[k * m]) * std::abs(ritzV[k * m]);
764749
}
765-
#ifdef HAS_OMP
766-
omp_set_num_threads(num_threads);
767-
#endif
750+
768751
delete[] isuppz;
769752
delete[] d;
770753
delete[] e;

ChASE-MPI/impl/chase_mpidla_blaslapack.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,28 +265,15 @@ class ChaseMpiDLABlaslapack : public ChaseMpiDLAInterface<T>
265265
//! within the row communicator.
266266
void Resd(Base<T>* ritzv, Base<T>* resid, std::size_t locked,
267267
std::size_t unconverged) override
268-
{
269-
#ifdef HAS_OMP
270-
char* omp_threads;
271-
omp_threads = getenv("OMP_NUM_THREADS");
272-
int num_threads = 1;
273-
if (omp_threads)
274-
{
275-
num_threads = std::atoi(omp_threads);
276-
}
277-
omp_set_num_threads(1);
278-
#endif
268+
{
279269
for (auto i = 0; i < unconverged; i++)
280270
{
281271
T alpha = -ritzv[i];
282272
t_axpy(n_, &alpha, B2_ + locked * n_ + i * n_, 1,
283273
B_ + locked * n_ + i * n_, 1);
284274

285275
resid[i] = t_norm_p2(n_, B_ + locked * n_ + i * n_);
286-
}
287-
#ifdef HAS_OMP
288-
omp_set_num_threads(num_threads);
289-
#endif
276+
}
290277
}
291278

292279
//! - This function performs the local computation for ChaseMpiDLA::heevd()

ChASE-MPI/impl/chase_mpidla_mgpu.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -636,16 +636,6 @@ class ChaseMpiDLAMultiGPU : public ChaseMpiDLAInterface<T>
636636
void Resd(Base<T>* ritzv, Base<T>* resid, std::size_t locked,
637637
std::size_t unconverged) override
638638
{
639-
#ifdef HAS_OMP
640-
char* omp_threads;
641-
omp_threads = getenv("OMP_NUM_THREADS");
642-
int num_threads = 1;
643-
if (omp_threads)
644-
{
645-
num_threads = std::atoi(omp_threads);
646-
}
647-
omp_set_num_threads(1);
648-
#endif
649639
for (auto i = 0; i < unconverged; i++)
650640
{
651641
T alpha = -ritzv[i];
@@ -655,9 +645,6 @@ class ChaseMpiDLAMultiGPU : public ChaseMpiDLAInterface<T>
655645
resid[i] = t_norm_p2(n_, B_ + locked * n_ + i * n_);
656646

657647
}
658-
#ifdef HAS_OMP
659-
omp_set_num_threads(num_threads);
660-
#endif
661648
}
662649
//! - This function performs the local computation for ChaseMpiDLA::heevd()
663650
//! - It is implemented based on `cuBLAS`'s `xgemm` and cuSOLVER's

algorithm/configuration.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,21 @@ class ChaseConfig
427427
*/
428428
std::size_t GetNex() const { return nex_; }
429429

430+
//! Sets the `cholqr_` flag to either `true` or `false`.
431+
/*! This function is used to change the value of `cholqr_` so
432+
either flexible CholQR (`true`) or Househoulder QR (`false`)
433+
will be used.
434+
\param flag A boolean parameter which admits either a `true` or `false`
435+
value.
436+
*/
437+
void SetCholQR(bool flag){
438+
cholqr_ = flag;
439+
}
440+
//! Return the value of `cholqr_`
441+
bool DoCholQR(){
442+
return cholqr_;
443+
}
444+
430445
private:
431446
///////////////////////////////////////////////////
432447
// General parameters of the eigensolver
@@ -542,6 +557,9 @@ class ChaseConfig
542557
default value is set to *4*.
543558
*/
544559
std::size_t num_lanczos_;
560+
561+
//! Optional parameter indicating if CholeksyQR is disabled
562+
bool cholqr_ = true;
545563
};
546564

547565
template <typename T>

examples/4_interface/4_c_dist_chase.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void pzchase_init_(int* N, int* nev, int* nex, int* m, int* n,
2323
double* ritzv, int* dim0, int* dim1, char* grid_major,
2424
MPI_Comm* comm, int* init);
2525
void pzchase_finalize_(int* flag);
26-
void pzchase_(int* deg, double* tol, char* mode, char* opt);
26+
void pzchase_(int* deg, double* tol, char* mode, char* opt, char *qr);
2727

2828
int main(int argc, char** argv)
2929
{
@@ -52,6 +52,7 @@ int main(int argc, char** argv)
5252
double tol = 1e-10;
5353
char mode = 'R';
5454
char opt = 'S';
55+
char qr = 'C';
5556

5657
if (N % dims[0] == 0)
5758
{
@@ -108,7 +109,7 @@ int main(int argc, char** argv)
108109
}
109110
}
110111

111-
pzchase_(&deg, &tol, &mode, &opt);
112+
pzchase_(&deg, &tol, &mode, &opt, &qr);
112113

113114
pzchase_finalize_(&init);
114115

examples/4_interface/4_c_serial_chase.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ double random_normal()
2727
int zchase_init_(int* N, int* nev, int* nex, double _Complex* H, int *ldh,
2828
double _Complex* V, double* ritzv, int* init);
2929
void zchase_finalize_();
30-
void zchase_(int* deg, double* tol, char* mode, char* opt);
30+
void zchase_(int* deg, double* tol, char* mode, char* opt, char *qr);
3131

3232
int main(int argc, char** argv)
3333
{
@@ -47,6 +47,7 @@ int main(int argc, char** argv)
4747
double tol = 1e-10;
4848
char mode = 'R';
4949
char opt = 'S';
50+
char qr = 'C';
5051

5152
if (rank == 0)
5253
printf("ChASE C example driver\n");
@@ -88,7 +89,7 @@ int main(int argc, char** argv)
8889
}
8990
}
9091

91-
zchase_(&deg, &tol, &mode, &opt);
92+
zchase_(&deg, &tol, &mode, &opt, &qr);
9293

9394
// Perturb Full Clement matrix
9495
for (int i = 1; i < N; ++i)

examples/4_interface/4_f_dist_chase.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ PROGRAM main
1616
real(8) :: tol
1717
complex(8) :: cv
1818
integer :: deg
19-
character :: mode, opt, major
19+
character :: mode, opt, major, qr
2020
complex(8), allocatable :: h(:,:), v(:,:), hh(:, :)
2121
real(8), allocatable :: lambda(:)
2222

@@ -35,6 +35,7 @@ PROGRAM main
3535
mode = 'R'
3636
opt = 'S'
3737
major = 'C'
38+
qr = 'C'
3839

3940
dims(1) = 0
4041
dims(2) = 0
@@ -85,7 +86,7 @@ PROGRAM main
8586
end do
8687
end do
8788

88-
call pzchase(deg, tol, mode, opt)
89+
call pzchase(deg, tol, mode, opt, qr)
8990

9091
call pzchase_finalize(init)
9192

examples/4_interface/4_f_serial_chase.f90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ PROGRAM main
1414
real(8) :: tol
1515
complex(8) :: cv
1616
integer :: deg
17-
character :: mode, opt
17+
character :: mode, opt, qr
1818
complex(8), allocatable :: h(:,:), v(:,:)
1919
real(8), allocatable :: lambda(:)
2020

@@ -33,6 +33,7 @@ PROGRAM main
3333
tol = 1e-10
3434
mode = 'R'
3535
opt = 'S'
36+
qr = 'C'
3637

3738
if(rank == 0) then
3839
print *, "ChASE Fortran example driver"
@@ -68,7 +69,7 @@ PROGRAM main
6869
end if
6970
end if
7071

71-
call zchase(deg, tol, mode, opt)
72+
call zchase(deg, tol, mode, opt, qr)
7273

7374
do i = 2, N
7475
do j = 2, i

0 commit comments

Comments
 (0)