ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
blacs_connector.h
Go to the documentation of this file.
1//------------------------------------>8======================================
2// Copyright (c) 2016, Yu Shen (shenyu@ustc.edu.cn)
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are met:
7// * Redistributions of source code must retain the above copyright
8// notice, this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above copyright
10// notice, this list of conditions and the following disclaimer in the
11// documentation and/or other materials provided with the distribution.
12// * Neither the name of the <organization> nor the
13// names of its contributors may be used to endorse or promote products
14// derived from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19// DISCLAIMED. IN NO EVENT Yu Shen SHALL BE LIABLE FOR ANY
20// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26//====================================8<----------------------------------------
27// blacs
28 // Initialization
29#ifndef BLACS_CONNECTOR_H
30#define BLACS_CONNECTOR_H
31
32#include <complex>
33
34extern "C"
35{
36 void Cblacs_pinfo(int *myid, int *nprocs);
37 void Cblacs_get(int icontxt, int what, int *val);
38 void Cblacs_gridmap(int* icontxt, int *usermap, int ldumap, int nprow, int npcol);
39 // Informational and Miscellaneous
40 void Cblacs_gridinfo(int icontxt, int* nprow, int *npcol, int *myprow, int *mypcol);
41 void Cblacs_gridinit(int* icontxt, char* layout, int nprow, int npcol);
42 void Cblacs_gridexit(int icontxt);
43 int Cblacs_pnum(int icontxt, int prow, int pcol);
44 void Cblacs_pcoord(int icontxt, int pnum, int *prow, int *pcol);
45 void Cblacs_exit(int icontxt);
46
47 // broadcast (send/recv)
48 void Cigebs2d(int ConTxt, char *scope, char *top, int m, int n, int *A, int lda);
49 void Cigebr2d(int ConTxt, char *scope, char *top, int m, int n, int *A, int lda, int rsrc, int csrc);
50
51 void Csgebs2d(int ConTxt, char *scope, char *top, int m, int n, float *A, int lda);
52 void Csgebr2d(int ConTxt, char *scope, char *top, int m, int n, float *A, int lda, int rsrc, int csrc);
53
54 void Cdgebs2d(int ConTxt, char *scope, char *top, int m, int n, double *A, int lda);
55 void Cdgebr2d(int ConTxt, char *scope, char *top, int m, int n, double *A, int lda, int rsrc, int csrc);
56
57 void Ccgebs2d(int ConTxt, char *scope, char *top, int m, int n, std::complex<float> *A, int lda);
58 void Ccgebr2d(int ConTxt, char *scope, char *top, int m, int n, std::complex<float> *A, int lda, int rsrc, int csrc);
59
60 void Czgebs2d(int ConTxt, char *scope, char *top, int m, int n, std::complex<double> *A, int lda);
61 void Czgebr2d(int ConTxt, char *scope, char *top, int m, int n, std::complex<double> *A, int lda, int rsrc, int csrc);
62}
63
64// unified interface for broadcast
65template <typename T>
66void Cxgebs2d(int ConTxt, char *scope, char *top, int m, int n, T *A, int lda)
67{
68 static_assert(
69 std::is_same<T, int>::value ||
70 std::is_same<T, float>::value ||
71 std::is_same<T, double>::value ||
72 std::is_same<T,std::complex<float>>::value ||
73 std::is_same<T,std::complex<double>>::value,
74 "Type not supported");
75
76 if (std::is_same<T, int>::value) {
77 Cigebs2d(ConTxt, scope, top, m, n, reinterpret_cast<int*>(A), lda);
78 }
79 if (std::is_same<T, float>::value) {
80 Csgebs2d(ConTxt, scope, top, m, n, reinterpret_cast<float*>(A), lda);
81 }
82 if (std::is_same<T, double>::value) {
83 Cdgebs2d(ConTxt, scope, top, m, n, reinterpret_cast<double*>(A), lda);
84 }
85 if (std::is_same<T, std::complex<float>>::value) {
86 Ccgebs2d(ConTxt, scope, top, m, n, reinterpret_cast<std::complex<float>*>(A), lda);
87 }
88 if (std::is_same<T, std::complex<double>>::value) {
89 Czgebs2d(ConTxt, scope, top, m, n, reinterpret_cast<std::complex<double>*>(A), lda);
90 }
91}
92
93template <typename T>
94void Cxgebr2d(int ConTxt, char *scope, char *top, int m, int n, T *A, int lda, int rsrc, int csrc)
95{
96 static_assert(
97 std::is_same<T, int>::value ||
98 std::is_same<T, float>::value ||
99 std::is_same<T, double>::value ||
100 std::is_same<T,std::complex<float>>::value ||
101 std::is_same<T,std::complex<double>>::value,
102 "Type not supported");
103
104 if (std::is_same<T, int>::value) {
105 Cigebr2d(ConTxt, scope, top, m, n, reinterpret_cast<int*>(A), lda, rsrc, csrc);
106 }
107 if (std::is_same<T, float>::value) {
108 Csgebr2d(ConTxt, scope, top, m, n, reinterpret_cast<float*>(A), lda, rsrc, csrc);
109 }
110 if (std::is_same<T, double>::value) {
111 Cdgebr2d(ConTxt, scope, top, m, n, reinterpret_cast<double*>(A), lda, rsrc, csrc);
112 }
113 if (std::is_same<T, std::complex<float>>::value) {
114 Ccgebr2d(ConTxt, scope, top, m, n, reinterpret_cast<std::complex<float>*>(A), lda, rsrc, csrc);
115 }
116 if (std::is_same<T, std::complex<double>>::value) {
117 Czgebr2d(ConTxt, scope, top, m, n, reinterpret_cast<std::complex<double>*>(A), lda, rsrc, csrc);
118 }
119}
120
121
122#ifdef __MPI
123#include <mpi.h>
124extern "C"
125{
126 int Csys2blacs_handle(MPI_Comm SysCtxt);
127 MPI_Comm Cblacs2sys_handle(int BlacsCtxt);
128}
129#endif // __MPI
130
131#endif
void Czgebr2d(int ConTxt, char *scope, char *top, int m, int n, std::complex< double > *A, int lda, int rsrc, int csrc)
void Cblacs_pcoord(int icontxt, int pnum, int *prow, int *pcol)
void Csgebr2d(int ConTxt, char *scope, char *top, int m, int n, float *A, int lda, int rsrc, int csrc)
void Ccgebr2d(int ConTxt, char *scope, char *top, int m, int n, std::complex< float > *A, int lda, int rsrc, int csrc)
void Cblacs_gridexit(int icontxt)
void Cblacs_get(int icontxt, int what, int *val)
void Cblacs_exit(int icontxt)
void Ccgebs2d(int ConTxt, char *scope, char *top, int m, int n, std::complex< float > *A, int lda)
void Cxgebr2d(int ConTxt, char *scope, char *top, int m, int n, T *A, int lda, int rsrc, int csrc)
Definition blacs_connector.h:94
void Cblacs_pinfo(int *myid, int *nprocs)
void Cigebs2d(int ConTxt, char *scope, char *top, int m, int n, int *A, int lda)
void Cxgebs2d(int ConTxt, char *scope, char *top, int m, int n, T *A, int lda)
Definition blacs_connector.h:66
void Cblacs_gridmap(int *icontxt, int *usermap, int ldumap, int nprow, int npcol)
int Cblacs_pnum(int icontxt, int prow, int pcol)
int Csys2blacs_handle(MPI_Comm SysCtxt)
void Cdgebs2d(int ConTxt, char *scope, char *top, int m, int n, double *A, int lda)
void Cigebr2d(int ConTxt, char *scope, char *top, int m, int n, int *A, int lda, int rsrc, int csrc)
void Csgebs2d(int ConTxt, char *scope, char *top, int m, int n, float *A, int lda)
void Cblacs_gridinfo(int icontxt, int *nprow, int *npcol, int *myprow, int *mypcol)
void Czgebs2d(int ConTxt, char *scope, char *top, int m, int n, std::complex< double > *A, int lda)
MPI_Comm Cblacs2sys_handle(int BlacsCtxt)
void Cdgebr2d(int ConTxt, char *scope, char *top, int m, int n, double *A, int lda, int rsrc, int csrc)
void Cblacs_gridinit(int *icontxt, char *layout, int nprow, int npcol)
#define T
Definition exp.cpp:237
int mypcol
Definition tddft_test.cpp:14
int nprow
Definition tddft_test.cpp:14
int myprow
Definition tddft_test.cpp:14
int npcol
Definition tddft_test.cpp:14