MapReduce-MPI WWW Site - MapReduce-MPI Documentation

### Copy a MapReduce object

    MapReduce *MapReduce::copy()

This calls the copy() method of a MapReduce object, which creates a second MapReduce object which is an exact copy of the first, including all settings, and returns a pointer to the new copy.

If the original MapReduce object contained a KeyValue or KeyMultiValue object, as discussed here, then the new MapReduce object will contain a copy of it. This means that all the key/value and/or key/multivalue pairs contained in the first MapReduce object are copied into the new MapReduce object. Thus the first MapReduce object could be subsequently deleted without affecting the new MapReduce object.

This is useful if you wish to retain a copy of a set of key/value pairs before processing it further. See the add() method for how to merge the key/value pairs from two MapReduce objects into one. For example, this sequence of calls:

    MapReduce *mr1 = new MapReduce(MPI_COMM_WORLD);
    mr1->map(ntasks,&mymap,NULL);
    MapReduce *mr2 = mr1->copy();
    mr2->collate();
    mr2->reduce(&myreduce2,NULL);
    mr1->add(mr2);
    delete mr2;
    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: create, add()