@@ -81,7 +81,7 @@ template void synchronizeFieldData<int>(FieldDataOf<int>*, Sharing*, bool);
8181template void synchronizeFieldData<double >(FieldDataOf<double >*, Sharing*, bool );
8282template void synchronizeFieldData<long >(FieldDataOf<long >*, Sharing*, bool );
8383
84- void reduceFieldData (FieldDataOf<double >* data, Sharing* shr, bool delete_shr, const ReductionOp< double >& reduce_op /* =ReductionSum<double>() */ )
84+ void accumulateFieldData (FieldDataOf<double >* data, Sharing* shr, bool delete_shr)
8585{
8686 FieldBase* f = data->getField ();
8787 Mesh* m = f->getMesh ();
@@ -91,26 +91,26 @@ void reduceFieldData(FieldDataOf<double>* data, Sharing* shr, bool delete_shr, c
9191 shr = getSharing (m);
9292 delete_shr=true ;
9393 }
94-
9594 for (int d=0 ; d < 4 ; ++d)
9695 {
9796 if ( ! s->hasNodesIn (d))
9897 continue ;
99-
10098 MeshEntity* e;
10199 MeshIterator* it = m->begin (d);
102100 PCU_Comm_Begin ();
103101 while ((e = m->iterate(it)))
104102 {
105- if (( ! data->hasEntity (e)) || m->isGhost (e) )
106- continue ; /* send to all parts that can see this entity */
103+ if (( ! data->hasEntity (e)) || m->isGhost (e) ||
104+ (shr->isOwned (e)))
105+ continue ; /* non-owners send to owners */
107106
108107 CopyArray copies;
109108 shr->getCopies (e, copies);
110109 int n = f->countValuesOn (e);
111110 NewArray<double > values (n);
112111 data->get (e,&(values[0 ]));
113-
112+ /* actually, non-owners send to all others,
113+ since apf::Sharing doesn't identify the owner */
114114 for (size_t i = 0 ; i < copies.getSize (); ++i)
115115 {
116116 PCU_COMM_PACK (copies[i].peer , copies[i].entity );
@@ -121,7 +121,8 @@ void reduceFieldData(FieldDataOf<double>* data, Sharing* shr, bool delete_shr, c
121121 PCU_Comm_Send ();
122122 while (PCU_Comm_Listen ())
123123 while ( ! PCU_Comm_Unpacked ())
124- { /* receive and apply reduction */
124+ { /* receive and add. we only care about correctness
125+ on the owners */
125126 MeshEntity* e;
126127 PCU_COMM_UNPACK (e);
127128 int n = f->countValuesOn (e);
@@ -130,15 +131,11 @@ void reduceFieldData(FieldDataOf<double>* data, Sharing* shr, bool delete_shr, c
130131 PCU_Comm_Unpack (&(inValues[0 ]),n*sizeof (double ));
131132 data->get (e,&(values[0 ]));
132133 for (int i = 0 ; i < n; ++i)
133- {
134- values[i] = reduce_op.apply (values[i], inValues[i]);
135- }
134+ values[i] += inValues[i];
136135 data->set (e,&(values[0 ]));
137136 }
138- }
139-
140- // every partition did the reduction, so no need to broadcast result
141- if (delete_shr) delete shr;
137+ } /* broadcast back out to non-owners */
138+ synchronizeFieldData (data, shr, delete_shr);
142139}
143140
144141template <class T >
0 commit comments