uint64_t MapReduce::add(MapReduce *mr2)
This calls the add() method of a MapReduce object, to add the KeyValue pairs contained in a second MapReduce object mr2, to the KeyValue object of the first MapReduce object, which is created if one does not exist. This is useful if multiple MapReduce objects have been created and populated with key/value pairs and you wish to combine them before performing further operations, such as a collate() and reduce().
For example, this sequence of calls:
MapReduce *mr1 = new MapReduce(MPI_COMM_WORLD); mr1->map(ntasks,&mymap,NULL); MapReduce *mr2 = mr1->copy(); mr2->collate(NULL); mr2->reduce(&myreduce2,NULL); mr1->add(mr2); delete mr2; mr1->collate(NULL); mr1->reduce(&myreduce1,NULL);
would generate one set of key/value pairs from the initial map() operation, then make a copy of them, which are then collated and reduced to a new set of key/value pairs. The new set of key/value pairs are added to the original set produced by the map() operation to form an augmented set of key/value pairs, which could be further processed.
Related methods: copy, map()