Loading...
Searching...
No Matches
scalapack.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * ScaLAPACK declarations for distributed complex double-precision routines.
5 *
6 * Provides the Fortran interfaces for BLACS grid management and distributed
7 * eigensolvers (PZHEGVX).
8 */
9
10#include <complex>
11
12#include <mpi.h>
13
14namespace q3::scalapack {
15
16extern "C" {
17
18/**
19 * BLACS grid management, C entry points.
20 *
21 * These must not be mixed with the Fortran `blacs_grid*_` entry points.
22 * Csys2blacs_handle returns a handle in the C layer's numbering space, and
23 * handing that to Fortran blacs_gridinit_ makes BLACS read it as a
24 * communicator: it returned 1 here, and MPICH then aborted inside
25 * MPI_Comm_group with "Invalid communicator, comm=0x1". Going through
26 * Cblacs_gridinit instead gives each communicator its own grid correctly.
27 *
28 * Csys2blacs_handle takes a C MPI_Comm, hence <mpi.h> above; typing it int
29 * would compile only where MPI_Comm is an integer (MPICH yes, OpenMPI no).
30 * Note also that Cblacs_gridinfo and Cblacs_gridexit take the context BY
31 * VALUE, unlike their Fortran counterparts which take a pointer.
32 *
33 * The system handle from Csys2blacs_handle is a separate resource from the grid
34 * context Cblacs_gridinit derives from it, and each needs releasing:
35 * Cblacs_gridexit for the grid, Cfree_blacs_system_handle for the handle.
36 */
37int Csys2blacs_handle(MPI_Comm mpi_comm);
38void Cfree_blacs_system_handle(int system_handle);
39void Cblacs_gridinit(int* context, const char* layout, int nprow, int npcol);
40void Cblacs_gridinfo(int context, int* nprow, int* npcol, int* myrow, int* mycol);
41void Cblacs_gridexit(int context);
42
43/**
44 * BLACS: Exit from BLACS.
45 */
46void blacs_exit_(const int* continue_mpi);
47
48/**
49 * DESCINIT: Initialize a ScaLAPACK descriptor.
50 */
51void descinit_(int* desc,
52 const int* m,
53 const int* n,
54 const int* mb,
55 const int* nb,
56 const int* irsrc,
57 const int* icsrc,
58 const int* ictxt,
59 const int* lld,
60 int* info);
61
62/**
63 * NUMROC: Compute number of rows/cols on a local process.
64 */
65int numroc_(const int* n, const int* nb, const int* iproc, const int* isrcproc, const int* nprocs);
66
67/**
68 * PZHEGVX: Parallel generalized Hermitian-definite eigenvalue problem.
69 *
70 * The expert driver, because it is the only one ScaLAPACK offers for the
71 * generalized problem. Q3 previously declared and called `pzhegv_`, the simple
72 * driver by analogy with LAPACK's ZHEGV -- but ScaLAPACK has no PZHEGV. The API
73 * provides PZHEEV, PZHEEVD and PZHEEVX for the standard problem and PZHEGVX
74 * alone for the generalized one, so every ScaLAPACK-enabled build failed to
75 * link with `undefined reference to pzhegv_' against any conforming
76 * implementation, Cray libsci included.
77 *
78 * Beyond PZHEGV's arguments this takes the eigenvalue selection (`range`, `vl`,
79 * `vu`, `il`, `iu`, `abstol`), returns how many it found (`m`) and how many
80 * eigenvectors it computed (`nz`), takes a reorthogonalization threshold
81 * (`orfac`), and needs integer workspace plus the `ifail`, `iclustr` and `gap`
82 * diagnostic arrays.
83 */
84void pzhegvx_(const int* ibtype,
85 const char* jobz,
86 const char* range,
87 const char* uplo,
88 const int* n,
89 std::complex<double>* a,
90 const int* ia,
91 const int* ja,
92 const int* desca,
93 std::complex<double>* b,
94 const int* ib,
95 const int* jb,
96 const int* descb,
97 const double* vl,
98 const double* vu,
99 const int* il,
100 const int* iu,
101 const double* abstol,
102 int* m,
103 int* nz,
104 double* w,
105 const double* orfac,
106 std::complex<double>* z,
107 const int* iz,
108 const int* jz,
109 const int* descz,
110 std::complex<double>* work,
111 const int* lwork,
112 double* rwork,
113 const int* lrwork,
114 int* iwork,
115 const int* liwork,
116 int* ifail,
117 int* iclustr,
118 double* gap,
119 int* info);
120
121} // extern "C"
122
123} // namespace q3::scalapack
void pzhegvx_(const int *ibtype, const char *jobz, const char *range, const char *uplo, const int *n, std::complex< double > *a, const int *ia, const int *ja, const int *desca, std::complex< double > *b, const int *ib, const int *jb, const int *descb, const double *vl, const double *vu, const int *il, const int *iu, const double *abstol, int *m, int *nz, double *w, const double *orfac, std::complex< double > *z, const int *iz, const int *jz, const int *descz, std::complex< double > *work, const int *lwork, double *rwork, const int *lrwork, int *iwork, const int *liwork, int *ifail, int *iclustr, double *gap, int *info)
void Cblacs_gridexit(int context)
void Cblacs_gridinfo(int context, int *nprow, int *npcol, int *myrow, int *mycol)
void Cblacs_gridinit(int *context, const char *layout, int nprow, int npcol)
int Csys2blacs_handle(MPI_Comm mpi_comm)
void blacs_exit_(const int *continue_mpi)
void Cfree_blacs_system_handle(int system_handle)
int numroc_(const int *n, const int *nb, const int *iproc, const int *isrcproc, const int *nprocs)
void descinit_(int *desc, const int *m, const int *n, const int *mb, const int *nb, const int *irsrc, const int *icsrc, const int *ictxt, const int *lld, int *info)