A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
AggOutProcessor.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 #ifndef AGGOUT_PROCESSOR_CC
19 #define AGGOUT_PROCESSOR_CC
20 
21 #include "AggOutProcessor.h"
22 
23 namespace pdb {
24 
25 // OutputClass must have getKey() and getValue() methods implemented
26 template <class OutputClass, class KeyType, class ValueType>
28 
29  finalized = false;
30  begin = nullptr;
31  end = nullptr;
32 }
33 
34 // initialize
35 template <class OutputClass, class KeyType, class ValueType>
37  finalized = false;
38 }
39 
40 // loads up another input page to process
41 template <class OutputClass, class KeyType, class ValueType>
43 
45  inputData = myRec->getRootObject();
46  if (begin != nullptr) {
47  delete begin;
48  }
49  if (end != nullptr) {
50  delete end;
51  }
52  begin = new PDBMapIterator<KeyType, ValueType>(inputData->getArray(), true);
53  end = new PDBMapIterator<KeyType, ValueType>(inputData->getArray());
54 }
55 
56 // loads up another output page to write results to
57 template <class OutputClass, class KeyType, class ValueType>
59  size_t numBytesInPage) {
60 
61  blockPtr = nullptr;
62  blockPtr = std::make_shared<UseTemporaryAllocationBlock>(pageToWriteTo, numBytesInPage);
63  outputData = makeObject<Vector<Handle<OutputClass>>>();
64  pos = 0;
65 }
66 
67 template <class OutputClass, class KeyType, class ValueType>
69 
70  // if we are finalized, see if there are some left over records
71  if (finalized) {
72  getRecord(outputData);
73  return false;
74  }
75 
76  // we are not finalized, so process the page
77  try {
78  // see if there are any more items in current map to iterate over
79  while (true) {
80 
81  if (!((*begin) != (*end))) {
82  PDB_COUT << "AggOutProcessor: processed " << pos << " elements in the input page"
83  << std::endl;
84  return false;
85  }
86 
87  Handle<OutputClass> temp = makeObject<OutputClass>();
88  temp->getKey() = (*(*begin)).key;
89  temp->getValue() = (*(*begin)).value;
90  outputData->push_back(temp);
91  pos++;
92  ++(*begin);
93  }
94 
95  } catch (NotEnoughSpace& n) {
96  getRecord(outputData);
97  return true;
98  }
99 }
100 
101 template <class OutputClass, class KeyType, class ValueType>
103  finalized = true;
104 }
105 
106 template <class OutputClass, class KeyType, class ValueType>
108  blockPtr = nullptr;
109  outputData = nullptr;
110 }
111 
112 template <class OutputClass, class KeyType, class ValueType>
114  inputData = nullptr;
115 }
116 }
117 
118 
119 #endif
Handle< ObjType > getRootObject()
Definition: Record.cc:46
Record< ObjType > * getRecord(Handle< ObjType > &forMe)
void loadOutputPage(void *pageToWriteTo, size_t numBytesInPage) override
void loadInputPage(void *pageToProcess) override
#define PDB_COUT
Definition: PDBDebug.h:31
void clearInputPage() override
void finalize() override
void clearOutputPage() override
bool fillNextOutputPage() override
void initialize() override