//CONFIG
        public void readSource()
        {
            Console.WriteLine(this.GlobalRank + ": STARTING SPLITTER READSOURCE...1");
            output_instance_gifs = (IIteratorInstance <IKVPair <IInteger, IIterator <GIF> > >)Output_gifs.Instance;
            Feed_graph.Server    = output_instance_gifs;
            Console.WriteLine(this.GlobalRank + ": STARTING SPLITTER READSOURCE...2");

            // RECEIVE PAIR FROM THE SOURCE (1st iteration)
            Tuple <int, int> unit_ref_source = new Tuple <int, int> (this.FacetIndexes [FACET_SOURCE] [0], 0);

            //	Thread[] threads_receive = new Thread[senders_size];

            //	for (int i = 0; i < senders_size; i++)
            //	{
            //		threads_receive [i] = new Thread ((ParameterizedThreadStart)delegate(object unit_ref_obj) {
            //			Tuple<int,int> unit_ref_i = (Tuple<int,int>)unit_ref_obj;
            //			receive_pairs_iteration (unit_ref_i);
            //		});
            //	}

            // TODO: READ_SOURCE é necessário ? Não no map feeder. Tirar fatia de Task_binding data ...

            Task_binding_data.TraceFlag = true;
            Task_binding_data.invoke(ITaskPortData.READ_SOURCE);
            // Do nothing ...


            IList <IKVPairInstance <IInteger, GIF> > buffer;
            object buffer_obj;

            CompletedStatus status;


            do
            {
                IActionFuture sync_perform;

                Console.WriteLine(this.Rank + ": SPLITTER MAP FEEDER - BEFORE READ_CHUNK");

                Task_binding_split_first.invoke(ITaskPortAdvance.READ_CHUNK);                   //****
                Task_binding_split_first.invoke(ITaskPortAdvance.PERFORM, out sync_perform);

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

                Console.WriteLine(this.Rank + ": SPLITTER MAP FEEDER !!! PERFORM OK !");

                Split_channel.Receive(unit_ref_source, MPI.Communicator.anyTag, out buffer, out status);

                Console.WriteLine(this.Rank + ": CHUNK PAIRS RECEIVED !!! from source buffer.Count=" + buffer.Count);

                //foreach (IKVPairInstance<IInteger,GIF> kv in buffer)
                //	output_instance_gif.put (kv);

                foreach (IKVPairInstance <IInteger, GIF> kv in buffer)
                {
                    IIteratorInstance <GIF> iterator = null;
                    if (!kv_cache.ContainsKey(kv.Key))
                    {
                        iterator = Value_factory_gif.newIteratorInstance();
                        kv_cache.Add(kv.Key, iterator);
                        IKVPairInstance <IInteger, IIterator <GIF> > item = (IKVPairInstance <IInteger, IIterator <GIF> >)Output_gifs.createItem();
                        item.Key   = kv.Key;
                        item.Value = iterator;
                        output_instance_gifs.put(item);
                    }
                    else
                    {
                        kv_cache.TryGetValue(kv.Key, out iterator);
                    }

                    iterator.put(kv.Value);
                }

                output_instance_gifs.finish();
                foreach (IIteratorInstance <IValue> iterator in kv_cache.Values)
                {
                    iterator.finish();
                }

                sync_perform.wait();

                // CHUNK_READY
                Console.WriteLine(this.Rank + ": SPLITTER MAP FEEDER 1");

                Task_binding_split_first.invoke(ITaskPortAdvance.CHUNK_READY);

                Console.WriteLine(this.Rank + ": SPLITTER MAP FEEDER 2");
            } while (status.Tag != TAG_SPLIT_END_CHUNK);

            output_instance_gifs.finish();

            Console.WriteLine(this.Rank + ": FINISH READING CHUNKS OF SOURCE");
        }
Exemplo n.º 2
0
        public void receive_write_gif(int senders_size, IDictionary <int, Tuple <int, int> > unit_ref)
        {
            IIteratorInstance <IKVPair <IInteger, IIterator <GIF> > > output_instance_gifs = (IIteratorInstance <IKVPair <IInteger, IIterator <GIF> > >)Output_gifs.Instance;

            Feed_graph.Server = output_instance_gifs;

            bool[] finished_stream = new bool[senders_size];
            for (int i = 0; i < senders_size; i++)
            {
                finished_stream [i] = false;
            }

            int count_finished_streams = 0;

            while (count_finished_streams < senders_size)                   // take next chunk ...
            {
                IActionFuture sync_perform;

                Task_binding_shuffle.invoke(ITaskPortAdvance.READ_CHUNK);
                Task_binding_shuffle.invoke(ITaskPortAdvance.PERFORM, out sync_perform);

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

                // PERFORM
                for (int i = 0; i < senders_size; i++)
                {
                    if (!finished_stream [i])
                    {
                        IList <IKVPairInstance <IInteger, GIF> > buffer;
                        CompletedStatus status;
                        Step_channel.Receive(unit_ref [i], MPI.Communicator.anyTag, out buffer, out status);

                        foreach (IKVPairInstance <IInteger, GIF> kv in buffer)
                        {
                            IIteratorInstance <GIF> iterator = null;
                            if (!kv_cache.ContainsKey(kv.Key))
                            {
                                iterator = Value_factory_gif.newIteratorInstance();
                                kv_cache.Add(kv.Key, iterator);
                                IKVPairInstance <IInteger, IIterator <GIF> > item = (IKVPairInstance <IInteger, IIterator <GIF> >)Output_gifs.createItem();
                                item.Key   = kv.Key;
                                item.Value = iterator;
                                output_instance_gifs.put(item);
                            }
                            else
                            {
                                kv_cache.TryGetValue(kv.Key, out iterator);
                            }

                            iterator.put(kv.Value);
                        }

                        if (status.Tag == TAG_SHUFFLE_OMV_END_CHUNK)
                        {
                            count_finished_streams++;
                            finished_stream [i] = true;
                        }
                    }
                }

                output_instance_gifs.finish();
                foreach (IIteratorInstance <GIF> iterator in kv_cache.Values)
                {
                    iterator.finish();
                }

                sync_perform.wait();

                // CHUNK_READY
                Task_binding_shuffle.invoke(ITaskPortAdvance.CHUNK_READY);                    //****
            }
            output_instance_gifs.finish();
            output_instance_gifs.finish();
        }