28 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
29 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
31 for (npcols =
int(sqrt(
double(nprocs))); npcols >= 1; --npcols)
33 if (nprocs % npcols == 0)
38 nprows = nprocs / npcols;
40 int *usermap =
new int[nprocs];
41 for (
int i = 0; i < nprows; i++)
43 for (
int j = 0; j < npcols; j++)
45 usermap[j * nprows + i] = i * npcols + j;
74 for (i = 0; i < n; i++)
76 if ((i % (nblk * nprows)) / nblk ==
myprow)
97 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
106 int SENDPROW = 0, SENDPCOL = 0, tag = 0;
107 T *tmp =
new T[nblk];
110 for (
int row = 0; row < nFull; row++)
112 int recv_prow = (row / nblk) % nprows;
113 int nm_row = ((row / nblk) / nprows) * nblk + row % nblk;
114 for (
int col = 0; col < nFull; col += nblk)
116 int recv_pcol = (col / nblk) % npcols;
117 int nm_col = ((col / nblk) / npcols) * nblk + col % nblk;
118 int pass_length = std::min(nFull - col, nblk);
124 for (
int i = 0; i < pass_length; i++)
126 new_matrix[(nm_col + i) * na_rows + nm_row] = hmatrix[nFull * row + col + i];
131 if (std::is_same<T, double>::value)
134 &(hmatrix[nFull * row + col]),
137 recv_prow * npcols + recv_pcol,
144 &(hmatrix[nFull * row + col]),
147 recv_prow * npcols + recv_pcol,
155 if (std::is_same<T, double>::value)
177 for (
int i = 0; i < pass_length; i++)
179 new_matrix[(nm_col + i) * na_rows + nm_row] = tmp[i];
195 int coef_row = row_first ? ncol : 1;
196 int coef_col = row_first ? 1 : nrow;
197 for (
int i = 0; i < nrow; i++)
199 for (
int j = 0; j < ncol; j++)
201 fp << std::setw(15) << matrix[i * coef_row + j * coef_col] <<
" ";
207template <
class T>
bool read_hs(std::string fname,
T &matrix)
210 std::ifstream inf(fname);
213 std::cout <<
"Error: open file " << fname <<
" failed, skip!" << std::endl;
217 matrix.resize(ndim * ndim);
218 for (
int i = 0; i < ndim; i++)
220 for (
int j = i; j < ndim; j++)
222 inf >> matrix[i * ndim + j];
225 matrix[j * ndim + i] = matrix[i * ndim + j];
240 const char jobz =
'V';
241 const char uplo =
'U';
242 int lwork = (nFull + 2) * nFull, info = 0;
243 double *ev =
new double[lwork];
245 double *a =
new double[nFull * nFull];
246 double *b =
new double[nFull * nFull];
247 for (
int i = 0; i < nFull * nFull; i++)
253 container::lapackConnector::hegv(
268 std::cout <<
"ERROR: solvered by LAPACK error, info=" << info << std::endl;
278 std::complex<double> *hmatrix,
279 std::complex<double> *smatrix,
284 const char jobz =
'V';
285 const char uplo =
'U';
286 int lwork = (nFull + 1) * nFull, info = 0;
287 double *rwork =
new double[3 * nFull - 2];
288 std::complex<double> *ev =
new std::complex<double>[lwork];
290 std::complex<double> *a =
new std::complex<double>[nFull * nFull];
291 std::complex<double> *b =
new std::complex<double>[nFull * nFull];
292 for (
int i = 0; i < nFull * nFull; i++)
298 container::lapackConnector::hegv(
314 std::cout <<
"ERROR: solvered by LAPACK error, info=" << info << std::endl;
This is a direct wrapper of some LAPACK routines. Column-Major version. Direct wrapping of standard L...
static void gridmap(int &context, int *usermap, int ldumap, int nprow, int npcol)
Definition blacs_connector.h:81
static void pinfo(int &rank, int &size)
Definition blacs_connector.h:75
static void get(int context, int what, int &value)
Definition blacs_connector.h:70
static void gridinfo(int context, int &nprow, int &npcol, int &myprow, int &mypcol)
Definition blacs_connector.h:86
#define T
Definition exp.cpp:237
Definition diago_elpa_utils.h:19
int na_rc(int n, int nblk, int nprows, int myprow)
Definition diago_elpa_utils.h:67
void process_2d(int &nprows, int &npcols, int &myprow, int &mypcol, int &icontxt)
Definition diago_elpa_utils.h:20
void print_matrix(std::ofstream &fp, T *matrix, int &nrow, int &ncol, bool row_first)
Definition diago_elpa_utils.h:188
void distribute_data(T *hmatrix, T *new_matrix, int &nFull, int &nblk, int &na_rows, int &na_cols, int &icontxt)
Definition diago_elpa_utils.h:87
void lapack_diago(double *hmatrix, double *smatrix, double *e, int &nFull)
Definition diago_elpa_utils.h:233
bool read_hs(std::string fname, T &matrix)
Definition diago_elpa_utils.h:207
int mypcol
Definition tddft_test.cpp:14
int myprow
Definition tddft_test.cpp:14