28 #ifndef _util_group_messaget_h
29 #define _util_group_messaget_h
31 #include <util/group/message.h>
37 GrpSumReduce<T>::reduce(T*target, T*data,
int nelement)
39 for (
int i=0; i<nelement; i++) {
46 GrpMinReduce<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];
55 GrpMaxReduce<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];
62 template <
class T,
class BinaryPredicate>
64 GrpCompareReduce<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];
73 GrpArithmeticAndReduce<T>::reduce(T*target, T*data,
int nelement)
75 for (
int i=0; i<nelement; i++) {
76 target[i] = target[i] & data[i];
82 GrpArithmeticOrReduce<T>::reduce(T*target, T*data,
int nelement)
84 for (
int i=0; i<nelement; i++) {
85 target[i] = target[i] | data[i];
91 GrpArithmeticXOrReduce<T>::reduce(T*target, T*data,
int nelement)
93 for (
int i=0; i<nelement; i++) {
94 target[i] = target[i] ^ data[i];
100 GrpProductReduce<T>::reduce(T*target, T*data,
int nelement)
102 for (
int i=0; i<nelement; i++) {
103 target[i] *= data[i];
109 GrpFunctionReduce<T>::reduce(T*target, T*data,
int nelement)
111 (*func_)(target,data,nelement);
114 template <
typename T>
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;