示例#1
0
        /// <summary>
        /// Send an object with a large serialized representation.
        /// </summary>
        /// <param name="comm"></param>
        /// <param name="value"></param>
        /// <param name="dest"></param>
        /// <param name="tag"></param>
        internal static void SendLarge <T>(Communicator comm, T value, int dest, int tag)
        {
            var batch = new BatchSendReceive();

            batch.ImmediateSend(comm, value, dest, tag);
            batch.WaitAll(comm);
        }
示例#2
0
        /// <summary>
        /// Scatter an object with large serialized representation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="comm"></param>
        /// <param name="isRoot"></param>
        /// <param name="values"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        public static T ScatterLarge <T>(Communicator comm, bool isRoot, T[] values, int root)
        {
            const int tag = 7;

            if (isRoot)
            {
                var batch = new BatchSendReceive();
                for (int destination = 0; destination < comm.Size; destination++)
                {
                    if (destination == root)
                    {
                        continue;
                    }
                    batch.ImmediateSend(comm, values[destination], destination, tag);
                }
                batch.WaitAll(comm);
                return(values[root]);
            }
            else
            {
                T value;
                ReceiveLarge(comm, root, tag, out value);
                return(value);
            }
        }
示例#3
0
        /// <summary>
        /// Gather an object with large serialized representation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="comm"></param>
        /// <param name="isRoot"></param>
        /// <param name="size"></param>
        /// <param name="inValue"></param>
        /// <param name="root"></param>
        /// <param name="outValues"></param>
        public static void GatherLarge <T>(Communicator comm, bool isRoot, int size, T inValue, int root, ref T[] outValues)
        {
            const int tag = 5;

            if (isRoot)
            {
                if (outValues == null || outValues.Length != size)
                {
                    outValues = new T[size];
                }

                var batch          = new BatchSendReceive();
                T[] outValuesLocal = outValues;
                for (int sender = 0; sender < size; sender++)
                {
                    if (sender == root)
                    {
                        outValues[sender] = inValue;
                        continue;
                    }
                    // make a copy since 'sender' is being modified
                    int senderLocal = sender;
                    batch.ImmediateReceive <T>(comm, sender, tag, value =>
                    {
                        outValuesLocal[senderLocal] = value;
                    });
                }
                batch.WaitAll(comm);
            }
            else
            {
                SendLarge(comm, inValue, root, tag);
            }
        }
示例#4
0
        /// <summary>
        /// Receive an object with a large serialized representation.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="comm"></param>
        /// <param name="source"></param>
        /// <param name="tag"></param>
        /// <param name="outValue"></param>
        public static void ReceiveLarge <T>(Communicator comm, int source, int tag, out T outValue)
        {
            var batch         = new BatchSendReceive();
            T   outValueLocal = default(T);

            batch.ImmediateReceive <T>(comm, source, tag, value =>
            {
                outValueLocal = value;
            });
            batch.WaitAll(comm);
            outValue = outValueLocal;
        }
示例#5
0
        public static void Alltoall <T>(Communicator comm, T[] inValues, T[] outValues, int[] sendCounts = null, int[] recvCounts = null)
        {
            SpanTimer.Enter("Alltoall");
            int tag   = Tag_Alltoall;
            var batch = new BatchSendReceive();

            for (int destination = 0; destination < comm.Size; destination++)
            {
                if (destination == comm.Rank)
                {
                    continue;
                }
                if (sendCounts != null && sendCounts[destination] == 0)
                {
                    continue;
                }
                batch.ImmediateSend(comm, inValues[destination], destination, tag);
            }
            for (int sender = 0; sender < comm.Size; sender++)
            {
                if (sender == comm.Rank)
                {
                    outValues[sender] = inValues[sender];
                    continue;
                }
                if (recvCounts != null && recvCounts[sender] == 0)
                {
                    continue;
                }
                // make a copy since 'sender' is being modified
                int senderLocal = sender;
                batch.ImmediateReceive <T>(comm, sender, tag, value =>
                {
                    outValues[senderLocal] = value;
                });
            }
            batch.WaitAll(comm);
            SpanTimer.Leave("Alltoall");
        }