9
/* size of internal buffer for global ops */
10
#define DGOP_BUF_SIZE 65536
11
#define IGOP_BUF_SIZE (sizeof(DoublePrecision)/sizeof(Integer))*DGOP_BUF_SIZE
13
static DoublePrecision gop_work[DGOP_BUF_SIZE]; /**< global ops buffer */
16
* global operations -- integer version
18
void IGOP_(Integer *ptype, Integer *x, Integer *pn, char *op, Integer oplen)
20
Integer *work = (Integer *) gop_work;
22
Integer buflen = TCG_MIN(nleft,IGOP_BUF_SIZE); /**< Try to get even sized buffers */
23
Integer nbuf = (nleft-1) / buflen + 1;
27
if(!_tcg_initialized){
28
TCGMSG_Comm = MPI_COMM_WORLD;
33
buflen = (nleft-1) / nbuf + 1;
35
if (strncmp(op,"abs",3) == 0) {
44
int ierr = MPI_SUCCESS;
45
int ndo = TCG_MIN(nleft, buflen);
47
if (strncmp(op,"+",1) == 0) {
48
ierr = MPI_Reduce(x, work, ndo, TCG_INT, MPI_SUM, root, TCGMSG_Comm);
49
} else if (strncmp(op,"*",1) == 0) {
50
ierr = MPI_Reduce(x, work, ndo, TCG_INT, MPI_PROD, root, TCGMSG_Comm);
51
} else if (strncmp(op,"max",3) == 0 || strncmp(op,"absmax",6) == 0) {
52
ierr = MPI_Reduce(x, work, ndo, TCG_INT, MPI_MAX, root, TCGMSG_Comm);
54
else if (strncmp(op,"min",3) == 0 || strncmp(op,"absmin",6) == 0) {
55
ierr = MPI_Reduce(x, work, ndo, TCG_INT, MPI_MIN, root, TCGMSG_Comm);
57
else if (strncmp(op,"or",2) == 0) {
58
ierr = MPI_Reduce(x, work, ndo, TCG_INT, MPI_BOR, root, TCGMSG_Comm);
60
Error("IGOP: unknown operation requested", (Integer) *pn);
62
tcgmsg_test_statusM("IGOP: MPI_Reduce:", ierr );
64
ierr = MPI_Bcast(work, ndo, TCG_INT, root, TCGMSG_Comm);
65
tcgmsg_test_statusM("IGOP: MPI_Bcast:", ierr);
72
nleft -= ndo; x+= ndo;
79
* global operations -- DoublePrecision version
81
void DGOP_(Integer *ptype, DoublePrecision *x, Integer *pn, char *op, Integer oplen)
83
DoublePrecision *work= gop_work;
85
Integer buflen = TCG_MIN(nleft,DGOP_BUF_SIZE); /**< Try to get even sized buffers */
86
Integer nbuf = (nleft-1) / buflen + 1;
89
buflen = (nleft-1) / nbuf + 1;
91
if (strncmp(op,"abs",3) == 0) {
100
int ierr = MPI_SUCCESS;
101
int ndo = TCG_MIN(nleft, buflen);
103
if (strncmp(op,"+",1) == 0) {
104
ierr = MPI_Reduce(x, work, ndo, TCG_DBL, MPI_SUM, root, TCGMSG_Comm);
105
} else if (strncmp(op,"*",1) == 0) {
106
ierr = MPI_Reduce(x, work, ndo, TCG_DBL, MPI_PROD, root, TCGMSG_Comm);
107
} else if (strncmp(op,"max",3) == 0 || strncmp(op,"absmax",6) == 0) {
108
ierr = MPI_Reduce(x, work, ndo, TCG_DBL, MPI_MAX, root, TCGMSG_Comm);
109
} else if (strncmp(op,"min",3) == 0 || strncmp(op,"absmin",6) == 0) {
110
ierr = MPI_Reduce(x, work, ndo, TCG_DBL, MPI_MIN, root, TCGMSG_Comm);
112
Error("DGOP: unknown operation requested", (Integer) *pn);
114
tcgmsg_test_statusM("DGOP: MPI_Reduce:", ierr );
116
ierr = MPI_Bcast(work, ndo, TCG_DBL, root, TCGMSG_Comm);
117
tcgmsg_test_statusM("DGOP: MPI_Bcast:", ierr );
124
nleft -= ndo; x+= ndo;
130
* Synchronize processes
132
void SYNCH_(Integer *type)
135
if(!_tcg_initialized){
136
TCGMSG_Comm = MPI_COMM_WORLD;
137
_tcg_initialized = 1;
140
MPI_Barrier(TCGMSG_Comm);
146
* broadcast buffer to all other processes from process originator
148
void BRDCST_(Integer *type, char *buf, Integer *lenbuf, Integer *originator)
150
/* hope that MPI int is large enough to store value in lenbuf */
151
int count = (int)*lenbuf, root = (int)*originator;
153
MPI_Bcast(buf, count, MPI_CHAR, root, TCGMSG_Comm);