41 #ifndef NCREDUCIBLEDATASOURCE_H_
42 #define NCREDUCIBLEDATASOURCE_H_
44 #include "NCDataSource.h"
45 #include "RepastProcess.h"
46 #include "TDataSource.h"
48 #include <boost/mpi.hpp>
50 #include <netcdfcpp.h>
58 template <
typename Op,
typename T>
71 virtual NcType ncType();
73 virtual void record();
74 virtual void write(NcVar* var);
78 template<
typename Op,
typename T>
80 dataSource_(dataSource), start(0) {
84 template<
typename Op,
typename T>
85 NCReducibleDataSource<Op, T>::~NCReducibleDataSource() {
88 template<
typename Op,
typename T>
89 NcType NCReducibleDataSource<Op, T>::ncType() {
90 return NcTypeTrait<T>::type;
93 template<
typename Op,
typename T>
94 void NCReducibleDataSource<Op, T>::record() {
95 data.push_back(dataSource_->getData());
98 template<
typename Op,
typename T>
99 void NCReducibleDataSource<Op, T>::write(NcVar* var) {
102 size_t size = data.size();
103 T* results =
new T[size];
104 reduce(*comm, &data[0], size, results, op_, 0);
106 var->set_cur(start, 0);
110 var->put(results, size, 1);
115 reduce(*comm, &data[0], data.size(), op_, 0);