Skip to content

Commit 9bf636a

Browse files
committed
Merge branch 'lanczos-modernize' into 'master'
Lanczos modernize See merge request SLai/ChASE!31
2 parents b17a381 + 3185e89 commit 9bf636a

11 files changed

Lines changed: 607 additions & 517 deletions

ChASE-MPI/chase_mpi.hpp

Lines changed: 3 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -554,74 +554,13 @@ class ChaseMpi : public chase::Chase<T>
554554
void Lanczos(std::size_t m, Base<T>* upperb) override
555555
{
556556
// todo
557-
std::size_t n = N_;
558557
Base<T>* d = new Base<T>[m]();
559558
Base<T>* e = new Base<T>[m]();
560559

561560
int idx_ = -1;
562561
Base<T> real_beta;
562+
dla_->Lanczos(m, idx_, d, e, &real_beta);
563563

564-
T alpha = T(1.0);
565-
T beta = T(0.0);
566-
T One = T(1.0);
567-
T Zero = T(0.0);
568-
569-
T* V1;
570-
T* V2;
571-
std::size_t ld;
572-
T* v0;
573-
T* v1;
574-
T* w;
575-
#ifdef USE_NSIGHT
576-
nvtxRangePushA("getLanczosBuffer2");
577-
#endif
578-
dla_->getLanczosBuffer2(&v0, &v1, &w);
579-
#ifdef USE_NSIGHT
580-
nvtxRangePop();
581-
#endif
582-
583-
#ifdef USE_NSIGHT
584-
nvtxRangePushA("Lanczos: loop");
585-
#endif
586-
// ENSURE that v1 has one norm
587-
Base<T> real_alpha = dla_->nrm2(n, v1, 1);
588-
alpha = T(1 / real_alpha);
589-
dla_->scal(n, &alpha, v1, 1);
590-
591-
for (std::size_t k = 0; k < m; k = k + 1)
592-
{
593-
dla_->applyVec(v1, w);
594-
595-
alpha = dla_->dot(n, v1, 1, w, 1);
596-
597-
alpha = -alpha;
598-
dla_->axpy(n, &alpha, v1, 1, w, 1);
599-
alpha = -alpha;
600-
601-
d[k] = std::real(alpha);
602-
603-
if (k == m - 1)
604-
break;
605-
606-
beta = T(-real_beta);
607-
dla_->axpy(n, &beta, v0, 1, w, 1);
608-
beta = -beta;
609-
610-
real_beta = dla_->nrm2(n, w, 1);
611-
612-
beta = T(1.0 / real_beta);
613-
614-
dla_->scal(n, &beta, w, 1);
615-
616-
e[k] = real_beta;
617-
618-
std::swap(v1, v0);
619-
std::swap(v1, w);
620-
}
621-
#ifdef USE_NSIGHT
622-
nvtxRangePop();
623-
#endif
624-
dla_->preApplication(v1, 0, 1);
625564
#ifdef USE_NSIGHT
626565
nvtxRangePushA("Stemr");
627566
#endif
@@ -663,71 +602,8 @@ class ChaseMpi : public chase::Chase<T>
663602
int idx_ = static_cast<int>(idx);
664603
Base<T> real_beta;
665604

666-
std::size_t n = N_;
605+
dla_->Lanczos(m, idx_, d, e, &real_beta);
667606

668-
T alpha = T(1.0);
669-
T beta = T(0.0);
670-
T One = T(1.0);
671-
T Zero = T(0.0);
672-
673-
T* V1;
674-
T* V2;
675-
std::size_t ld;
676-
T* v0;
677-
T* v1;
678-
T* w;
679-
#ifdef USE_NSIGHT
680-
nvtxRangePushA("getLanczosBuffer");
681-
#endif
682-
dla_->getLanczosBuffer(&V1, &V2, &ld, &v0, &v1, &w);
683-
#ifdef USE_NSIGHT
684-
nvtxRangePop();
685-
nvtxRangePushA("C2V");
686-
#endif
687-
dla_->C2V(V2, idx, v1, 0, 1);
688-
#ifdef USE_NSIGHT
689-
nvtxRangePop();
690-
#endif
691-
// ENSURE that v1 has one norm
692-
#ifdef USE_NSIGHT
693-
nvtxRangePushA("Lanczos: loop");
694-
#endif
695-
Base<T> real_alpha = dla_->nrm2(n, v1, 1);
696-
alpha = T(1 / real_alpha);
697-
dla_->scal(n, &alpha, v1, 1);
698-
for (std::size_t k = 0; k < m; k = k + 1)
699-
{
700-
dla_->V2C(v1, 0, V1, k, 1);
701-
dla_->applyVec(v1, w);
702-
alpha = dla_->dot(n, v1, 1, w, 1);
703-
alpha = -alpha;
704-
dla_->axpy(n, &alpha, v1, 1, w, 1);
705-
alpha = -alpha;
706-
707-
d[k] = std::real(alpha);
708-
709-
if (k == m - 1)
710-
break;
711-
712-
beta = T(-real_beta);
713-
dla_->axpy(n, &beta, v0, 1, w, 1);
714-
beta = -beta;
715-
716-
real_beta = dla_->nrm2(n, w, 1);
717-
718-
beta = T(1.0 / real_beta);
719-
720-
dla_->scal(n, &beta, w, 1);
721-
722-
e[k] = real_beta;
723-
724-
std::swap(v1, v0);
725-
std::swap(v1, w);
726-
}
727-
#ifdef USE_NSIGHT
728-
nvtxRangePop();
729-
#endif
730-
dla_->preApplication(v1, 0, 1);
731607
#ifdef USE_NSIGHT
732608
nvtxRangePushA("Stemr");
733609
#endif
@@ -738,7 +614,7 @@ class ChaseMpi : public chase::Chase<T>
738614
int* isuppz = new int[2 * m];
739615
t_stemr(LAPACK_COL_MAJOR, 'V', 'A', m, d, e, ul, ll, vl, vu,
740616
&notneeded_m, ritzv, ritzV, m, m, isuppz, &tryrac);
741-
*upperb = std::max(std::abs(ritzv[0]), std::abs(ritzv[m - 1])) +
617+
*upperb = std::max(std::abs(ritzv[0]), std::abs(ritzv[m - 1])) +
742618
std::abs(real_beta);
743619
#ifdef USE_NSIGHT
744620
nvtxRangePop();
@@ -775,26 +651,6 @@ class ChaseMpi : public chase::Chase<T>
775651
}
776652
#endif
777653

778-
// if distributed ChASE is used, collecting the distributed ritz vectors
779-
// into V which is redundant across all MPI ranks. if non-distributed ChASE
780-
// is used, copying Ritz vectors directly to V
781-
//! When distributed ChASE is used, this member function collects the
782-
//! partially distributed Ritz vectors into a redundant vectors `V` on all
783-
//! MPI procs.
784-
//! @param V: the buffer of size `N_xnev_` which stores the collected
785-
//! redundant Ritz vectors.
786-
void collectRitzVecs(T* V)
787-
{
788-
#ifdef USE_NSIGHT
789-
nvtxRangePushA("collectRitzVecs");
790-
#endif
791-
T* Vv = matrices_.get_V1();
792-
dla_->C2V(Vv, 0, V, 0, nev_);
793-
#ifdef USE_NSIGHT
794-
nvtxRangePop();
795-
#endif
796-
}
797-
798654
//! \return `H_`: A pointer to the memory allocated to store (local part if
799655
//! applicable) of matrix `A`.
800656
T* GetMatrixPtr() { return matrices_.get_H(); }

ChASE-MPI/chase_mpidla_interface.hpp

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -129,42 +129,7 @@ class ChaseMpiDLAInterface
129129
*/
130130
virtual void asynCxHGatherC(std::size_t locked, std::size_t block,
131131
bool isCcopied = false) = 0;
132-
133-
//! Copy from buffer rectangular matrix `v1` to `v2`.
134-
//! For the implementation of distributed-memory ChASE, this operation
135-
//! performs a `copy` from a matrix redundantly distributed across all MPI
136-
//! procs to a matrix distributed within each column communicator and
137-
//! redundant among different column communicators. This operation is
138-
//! reciprocal to V2C().
139-
/*!
140-
* @param v1: the buffer to copy from
141-
* @param off1: the offset for the starting column index of `v1` to copy
142-
* from
143-
* @param v2: the buffer to copy to
144-
* @param off2: the offset for the starting column index of `v2` to copy to
145-
* @param block: number of columns to copy from `v1` to `v2`
146-
*/
147-
virtual void C2V(T* v1, std::size_t off1, T* v2, std::size_t off2,
148-
std::size_t block) = 0;
149-
//! Copy from buffer rectangular matrix `v1` to `v2`.
150-
//! For the implementation of distributed-memory ChASE, this operation
151-
//! performs a `copy` from a matrix distributed within each column
152-
//! communicator and redundant among different column communicators to a
153-
//! matrix redundantly distributed across all MPI procs. This operation is
154-
//! reciprocal to C2V(). It requires the `dim_[0]` MPI broadcasting
155-
//! operations, in which `dim_[0]` is the size of each MPI column
156-
//! communicatior.
157-
/*!
158-
* @param v1: the buffer to copy from
159-
* @param off1: the offset for the starting column index of `v1` to copy
160-
* from
161-
* @param v2: the buffer to copy to
162-
* @param off2: the offset for the starting column index of `v2` to copy to
163-
* @param block: number of columns to copy from `v1` to `v2`
164-
*/
165-
virtual void V2C(T* v1, std::size_t off1, T* v2, std::size_t off2,
166-
std::size_t block) = 0;
167-
132+
168133
//! Swap the columns indexing `i` and `j` in a rectangular matrix
169134
//! The operated matrices maybe different in different implementations
170135
/*!
@@ -371,25 +336,13 @@ class ChaseMpiDLAInterface
371336
//! Cholesky QR factorization on the rectangular matrix `V1`.
372337
//! @param locked: number of converged eigenvectors.
373338
virtual void cholQR(std::size_t locked, Base<T> cond) = 0;
374-
//! Return the required buffers of Lanczos which are allocated within each
375-
//! individual implementation of DLA. This operation is required, since
376-
//! Lanczos algorithm is implemented in ChaseMpi class, which has no direct
377-
//! access to these buffers. Depending on the implementation and targeting
378-
//! architectures, these buffers can be on CPU or GPUs.
379-
//! **This function will be removed in short future in which all the buffers
380-
//! will be allocated within ChaseMpiMatrices**.
381-
virtual void getLanczosBuffer(T** V1, T** V2, std::size_t* ld, T** v0,
382-
T** v1, T** w) = 0;
383-
//! Return the required buffers of Lanczos which are allocated within each
384-
//! individual implementation of DLA. This operation is required, since
385-
//! Lanczos algorithm is implemented in ChaseMpi class, which has no direct
386-
//! access to these buffers. Depending on the implementation and targeting
387-
//! architectures, these buffers can be on CPU or GPUs.
388-
//! **This function will be removed in short future in which all the buffers
389-
//! will be allocated within ChaseMpiMatrices**.
390-
virtual void getLanczosBuffer2(T** v0, T** v1, T** w) = 0;
391339
//! Lanczos DOS to estimate the \mu_{nev+nex} for ChASE
392340
virtual void LanczosDos(std::size_t idx, std::size_t m, T* ritzVc) = 0;
341+
342+
virtual void Lanczos(std::size_t M, int idx, Base<T>* d, Base<T>* e, Base<T> *r_beta) = 0;
343+
344+
virtual void B2C(T* B, std::size_t off1, T* C, std::size_t off2, std::size_t block) = 0;
345+
393346
};
394347
} // namespace mpi
395348
} // namespace chase

0 commit comments

Comments
 (0)