28#ifndef _util_group_messaget_h
29#define _util_group_messaget_h
31#include <util/group/message.h>
37GrpSumReduce<T>::reduce(T*target, T*data,
int nelement)
39 for (
int i=0; i<nelement; i++) {
46GrpMinReduce<T>::reduce(T*target, T*data,
int nelement)
48 for (
int i=0; i<nelement; i++) {
49 if (target[i] > data[i]) target[i] = data[i];
55GrpMaxReduce<T>::reduce(T*target, T*data,
int nelement)
57 for (
int i=0; i<nelement; i++) {
58 if (target[i] < data[i]) target[i] = data[i];
62template <
class T,
class BinaryPredicate>
64GrpCompareReduce<T, BinaryPredicate>::reduce(T*target, T*data,
int nelement)
66 for (
int i=0; i<nelement; i++) {
67 if (Op(target[i], data[i])) target[i] = data[i];
73GrpArithmeticAndReduce<T>::reduce(T*target, T*data,
int nelement)
75 for (
int i=0; i<nelement; i++) {
76 target[i] = target[i] & data[i];
82GrpArithmeticOrReduce<T>::reduce(T*target, T*data,
int nelement)
84 for (
int i=0; i<nelement; i++) {
85 target[i] = target[i] | data[i];
91GrpArithmeticXOrReduce<T>::reduce(T*target, T*data,
int nelement)
93 for (
int i=0; i<nelement; i++) {
94 target[i] = target[i] ^ data[i];
100GrpProductReduce<T>::reduce(T*target, T*data,
int nelement)
102 for (
int i=0; i<nelement; i++) {
103 target[i] *= data[i];
109GrpFunctionReduce<T>::reduce(T*target, T*data,
int nelement)
111 (*func_)(target,data,nelement);
117 T* scratch,
int target)
119 int tgop_max = gop_max_/
sizeof(T);
120 if (tgop_max == 0) tgop_max = gop_max_?1:
n;
124 scratch =
new T[
n>tgop_max?tgop_max:
n];
127 else passed_scratch = 1;
130 (target== -1?0:target)));
131 for (i->backwards(); !i->done(); i->next()) {
132 for (
int idat=0; idat<
n; idat+=tgop_max) {
133 int ndat = (idat+tgop_max>
n)?(
n-idat):tgop_max;
135 raw_send(i->sendto(), &data[idat], ndat*
sizeof(T));
138 raw_recv(i->recvfrom(), scratch, ndat*
sizeof(T));
139 red.reduce(&data[idat], scratch, ndat);
142 if (
n > tgop_max)
sync();
146 raw_bcast(data,
n*
sizeof(T), 0);
149 if (!passed_scratch)
delete[] scratch;
virtual void sync()
Synchronize all of the processors.
void reduce(T *, int n, GrpReduce< T > &, T *scratch=0, int target=-1)
T must be a POD (plain old data) type so that it can be copied bytewise.
Definition messaget.h:116
int n()
Returns the number of processors.
Definition message.h:192
A template class that maintains references counts.
Definition ref.h:361
Contains all MPQC code up to version 3.
Definition mpqcin.h:14