/* Recebimento de ORVs das unidades source */
        public void receiveCombineORVs()
        {
            int listenFinishedObject = 0;

            Trace.WriteLine(WorldComm.Rank + ": START COMBINER TARGET !!!");

            object orv;

            MPI.CompletedStatus status;
            while (listenFinishedObject < size_reducers)
            {
                Trace.WriteLine(WorldComm.Rank + ": BEGIN RECEIVE COMBINER TARGET to ");
                comm.Receive <object>(MPI.Unsafe.MPI_ANY_SOURCE, MPI.Unsafe.MPI_ANY_TAG, out orv, out status);
                Trace.WriteLine(WorldComm.Rank + ": END RECEIVE COMBINER TARGET to " + (status.Source));

                if (status.Tag == TAG_COMBINER_ORV_FINISH)
                {
                    listenFinishedObject = listenFinishedObject + 1;
                }
                else
                {
                    combine_input_data_instance.put(orv);
                }
            }

            combine_input_data_instance.finish();

            Trace.WriteLine(WorldComm.Rank + ": FINISH COMBINER TARGET !!!");
        }
Exemplo n.º 2
0
        public override void main()
        {
            int count = 0;

            // 1. recebe os bins enviados pelo gerente (unidade source),
            //    através do MPI, e os insere no Target_data.

            Trace.WriteLine(WorldComm.Rank + ": STARTING SCATTER SPLIT DATA TARGET");

            MPI.CompletedStatus status;
            int    source_rank = this.UnitRanks["source"][0];
            object bin_key;
            object bin_value;

            IIteratorInstance <IKVPair <IMK, IMV> > target_data_instance = (IIteratorInstance <IKVPair <IMK, IMV> >)Target_data.Instance;

            Trace.WriteLine(WorldComm.Rank + ": BEGIN RECEIVE BIN KEY from " + source_rank + "count=" + (count++));
            comm.Receive <object> (source_rank, MPI.Unsafe.MPI_ANY_TAG, out bin_key, out status);
            Trace.WriteLine(WorldComm.Rank + ": END RECEIVE BIN KEY from " + source_rank);
            while (status.Tag != TAG_SPLITTER_IMK_FINISH)
            {
                Trace.WriteLine(WorldComm.Rank + ": BEGIN RECEIVE BIN VALUE from " + source_rank);
                comm.Receive <object> (source_rank, TAG_SPLITTER_IMV, out bin_value, out status);
                Trace.WriteLine(WorldComm.Rank + ": END RECEIVE BIN VALUE from " + source_rank);
                IKVPairInstance <IMK, IMV> pair = (IKVPairInstance <IMK, IMV>)Target_data.createItem();
                pair.Key   = bin_key;
                pair.Value = bin_value;
                target_data_instance.put(pair);
                Trace.WriteLine(WorldComm.Rank + ": BEGIN RECEIVE BIN KEY from " + source_rank + "count=" + (count++));
                comm.Receive <object> (source_rank, MPI.Unsafe.MPI_ANY_TAG, out bin_key, out status);
                Trace.WriteLine(WorldComm.Rank + ": END RECEIVE BIN KEY from " + source_rank);
            }

            Trace.WriteLine(WorldComm.Rank + ": FINISH ALL BIN KEYs #1 !!!");
            target_data_instance.finish();
            Trace.WriteLine(WorldComm.Rank + ": FINISH ALL BIN KEYs #2 !!!");
        }
        public override void main()
        {
            Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) - START ");
            MPI.CompletedStatus        status;
            IKVPairInstance <OMK, OMV> kv;

            int senders_size = this.UnitSize ["mapper"];

            IIteratorInstance <IKVPair <OMK, IIterator <OMV> > > reduce_job_instance = (IIteratorInstance <IKVPair <OMK, IIterator <OMV> > >)Reduce_job.Instance;

            IDictionary <object, IIteratorInstance <OMV> > kv_cache = new Dictionary <object, IIteratorInstance <OMV> >();

            int finished_senders = 0;

            Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) BEGIN RECEIVE 1 !");
            comm.Receive <IKVPairInstance <OMK, OMV> >(MPI.Unsafe.MPI_ANY_SOURCE, MPI.Unsafe.MPI_ANY_TAG, out kv, out status);
            Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) END RECEIVE 1  ! tag=" + status.Tag + ", source=" + status.Source);

            int  count         = 0;
            bool last_finished = false;

            if (status.Tag == TAG_FETCHVALUES_OMV_FINISH)
            {
                finished_senders++;
                last_finished = true;
            }

            while (finished_senders < senders_size)
            {
                if (!last_finished)
                {
                    IIteratorInstance <OMV> iterator = null;
                    if (!kv_cache.ContainsKey(kv.Key))
                    {
                        Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) LOOP RECV 1 !" + (count++) + " " + kv.Key.GetType());
                        iterator = Reduce_job_values_factory.newIteratorInstance();
                        kv_cache.Add(kv.Key, iterator);
                        IKVPairInstance <OMK, IIterator <OMV> > item = (IKVPairInstance <OMK, IIterator <OMV> >)Reduce_job.createItem();
                        item.Key   = kv.Key;
                        item.Value = iterator;
                        reduce_job_instance.put(item);
                    }
                    else
                    {
                        Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) LOOP RECV 2 !" + (count++));
                        kv_cache.TryGetValue(kv.Key, out iterator);
                    }
                    iterator.put(kv.Value);
                }
                else
                {
                    last_finished = false;
                    Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) - FINISH DETECTED ");
                }

                Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) BEGIN RECEIVE n !");
                comm.Receive <IKVPairInstance <OMK, OMV> >(MPI.Unsafe.MPI_ANY_SOURCE, MPI.Unsafe.MPI_ANY_TAG, out kv, out status);
                Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) END RECEIVE n ! tag=" + status.Tag + ", source=" + status.Source);

                if (status.Tag == TAG_FETCHVALUES_OMV_FINISH)
                {
                    finished_senders++;
                    last_finished = true;
                }
            }

            foreach (KeyValuePair <object, IIteratorInstance <OMV> > kv_item in kv_cache)
            {
                kv_item.Value.finish();
            }

            reduce_job_instance.finish();
            Trace.WriteLine(Rank + ": PARTITIONER (FETCH VALUES TARGET) - FINISH ");
        }