Example #1
0
        public void Reduce <T> (int facet, T[] inValues, ReductionOperation <T> op, int root, ref T[] outValues)
        {
            int conversation_tag = takeNextConversationTag();

            this.RootCommunicator.Send <Tuple <int, int> >(new Tuple <int, int>(AliencommunicatorOperation.REDUCE_ARRAY, conversation_tag), 0, TAG_SEND_OPERATION + 0);
            throw new NotImplementedException();
        }
        public void ReduceScatter <T> (int facet, T[] inValues, ReductionOperation <T> op, int[] counts, ref T[] outValues)
        {
            int conversation_tag = takeNextConversationTag();

            /* lock (lock_mpi) */ this.RootCommunicator.Send <Tuple <int, int> >(new Tuple <int, int>(AliencommunicatorOperation.REDUCE_SCATTER, conversation_tag), 0, TAG_SEND_OPERATION + 0);
            throw new NotImplementedException();
        }
Example #3
0
        internal T Reduce_impl <T>(int facet, bool isRoot, int size, T value, ReductionOperation <T> op, int root)
        {
            int conversation_tag = takeNextConversationTag();

            this.RootCommunicator.Send <Tuple <int, int> >(new Tuple <int, int>(AliencommunicatorOperation.REDUCE, conversation_tag), 0, TAG_SEND_OPERATION + 0);
            throw new NotImplementedException();
        }
Example #4
0
        // All Reduce

        public T Allreduce <T> (int facet, T value, ReductionOperation <T> op)
        {
            int conversation_tag = takeNextConversationTag();

            this.RootCommunicator.Send <Tuple <int, int> >(new Tuple <int, int>(AliencommunicatorOperation.ALL_REDUCE, conversation_tag), 0, TAG_SEND_OPERATION + 0);
            throw new NotImplementedException();
        }
Example #5
0
        /// <summary>
        /// Create a user-defined MPI operation based on the given reduction operation.
        /// </summary>
        /// <param name="op">The reduction operation.</param>
        public Operation(ReductionOperation <T> op)
        {
            // Try to find the predefined MPI operation
            mpiOp = GetPredefinedOperation(op);

            if (mpiOp == Unsafe.MPI_OP_NULL)
            {
                // Since we could not find a predefined operation, wrap up the user's operation
                // in a delegate that matches the signature of MPI_User_function

                unsafe
                {
                    // Create the MPI_Op from the wrapper delegate
                    if (UseGeneratedUserOps)
                    {
                        wrapperDelegate = MakeMPIDelegate(op);
                    }
                    else
                    {
                        WrapReductionOperation wrapper = new WrapReductionOperation(op);
                        wrapperDelegate = new MPIDelegate(wrapper.Apply);
                    }
                    int errorCode = Unsafe.MPI_Op_create(Marshal.GetFunctionPointerForDelegate(wrapperDelegate), 0, out mpiOp);
                    if (errorCode != Unsafe.MPI_SUCCESS)
                    {
                        throw Environment.TranslateErrorIntoException(errorCode);
                    }
                }
            }
        }
Example #6
0
 T[] Aliencommunicator.Reduce <T> (int facet, T[] values, ReductionOperation <T> op, int root)
 {
     this.RootCommunicator.Send <AliencommunicatorOperation>(AliencommunicatorOperation.REDUCE, 0, TAG_SEND_OPERATION + 1);
     return(alien_communicator.Reduce <T> (facet, values, op, root));
 }
Example #7
0
        // Reduce Array

        public T[] Reduce <T> (int facet, T[] values, ReductionOperation <T> op, int root)
        {
            T[] result = null;
            Reduce(facet, values, op, root, ref result);
            return(result);
        }
Example #8
0
        // Reduce

        public T Reduce <T> (int facet, T value, ReductionOperation <T> op, int root)
        {
            return(Reduce_impl <T>(facet, (root == Root), RemoteSize, value, op, root));
        }
Example #9
0
        // Reduce-Scatter

        public T[] ReduceScatter <T> (int facet, T[] values, ReductionOperation <T> op, int[] counts)
        {
            T[] result = null;
            ReduceScatter(facet, values, op, counts, ref result);
            return(result);
        }
Example #10
0
        // All Reduce Array

        public T[] Allreduce <T> (int facet, T[] values, ReductionOperation <T> op)
        {
            T[] result = null;
            Allreduce(facet, values, op, ref result);
            return(result);
        }
Example #11
0
 public ReductionOperationView(ReductionOperation content)
     : this()
 {
     Content = content;
 }
Example #12
0
 public UserOperations(ReductionOperation <T> op) : base(op)
 {
 }
Example #13
0
 void Aliencommunicator.ReduceScatter <T> (int facet, T[] inValues, ReductionOperation <T> op, int[] counts, ref T[] outValues)
 {
     this.RootCommunicator.Send <AliencommunicatorOperation>(AliencommunicatorOperation.REDUCE_SCATTER, 0, TAG_SEND_OPERATION + 1);
     alien_communicator.ReduceScatter <T> (facet, inValues, op, counts, ref outValues);
 }
Example #14
0
        // Reduce-Scatter

        T[] Aliencommunicator.ReduceScatter <T> (int facet, T[] values, ReductionOperation <T> op, int[] counts)
        {
            this.RootCommunicator.Send <AliencommunicatorOperation>(AliencommunicatorOperation.REDUCE_SCATTER, 0, TAG_SEND_OPERATION + 0);
            return(alien_communicator.ReduceScatter <T> (facet, values, op, counts));
        }
Example #15
0
        // All Reduce

        T Aliencommunicator.Allreduce <T> (int facet, T value, ReductionOperation <T> op)
        {
            this.RootCommunicator.Send <AliencommunicatorOperation>(AliencommunicatorOperation.ALL_REDUCE, 0, TAG_SEND_OPERATION + 0);
            return(alien_communicator.Allreduce <T> (facet, value, op));
        }
Example #16
0
 /// <summary>
 /// Construct a new reduction operation wrapper.
 /// </summary>
 public WrapReductionOperation(ReductionOperation <T> op)
 {
     this.op = op;
 }
Example #17
0
        /// <summary>
        /// Creates a new MPI delegate from a reduction operation.
        /// </summary>
        private MPIDelegate MakeMPIDelegate(ReductionOperation <T> op)
        {
            if (mpiDelegateMethod == null)
            {
                unsafe
                {
                    // Build the new mpiDelegateMethod
                    mpiDelegateMethod =
                        new DynamicMethod("reduce:" + typeof(T).ToString(),
                                          typeof(void),
                                          //                     op                       invec        inoutvec       count           datatype
                                          new Type[] { typeof(ReductionOperation <T>), typeof(void *), typeof(void *), typeof(int *), typeof(MPI_Datatype *) },
                                          typeof(ReductionOperation <T>));
                }
                ILGenerator generator = mpiDelegateMethod.GetILGenerator();

                // Local variables:
                /*loopCounter*/ generator.DeclareLocal(typeof(int));
                /*count*/ generator.DeclareLocal(typeof(int));

                // Labels we'll be using to jump around
                Label loopStart = generator.DefineLabel();
                Label loopDone  = generator.DefineLabel();

                // Initialize loopCounter with zero
                generator.Emit(OpCodes.Ldc_I4_0);
                generator.Emit(OpCodes.Stloc_0);

                // Load the count into "count"
                generator.Emit(OpCodes.Ldarg_3);
                generator.Emit(OpCodes.Ldind_I4); // TODO: Can we assume "int" is always 32 bits? It is for Windows 32- and 64-bit
                generator.Emit(OpCodes.Stloc_1);

                // We're at the beginning of the loop
                generator.MarkLabel(loopStart);

                // Test to see whether we're done. If so, jump to loopDone
                generator.Emit(OpCodes.Ldloc_0);
                generator.Emit(OpCodes.Ldloc_1);
                generator.Emit(OpCodes.Clt);
                generator.Emit(OpCodes.Brfalse, loopDone);

                // Load the address of inoutvec[loopCounter] onto the stack, to be used after we invoke the delegate
                generator.Emit(OpCodes.Ldarg_2);

                // Load the delegate onto the stack
                generator.Emit(OpCodes.Ldarg_0);

                // Load the first argument (invec[loopCounter]) to the user delegate
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Ldobj, typeof(T));

                // Load the second argument (inoutvec[loopCounter]) to the user delegate
                generator.Emit(OpCodes.Ldarg_2);
                generator.Emit(OpCodes.Ldobj, typeof(T));

                // Call the delegate
                generator.EmitCall(OpCodes.Callvirt,
                                   typeof(ReductionOperation <T>).GetMethod("Invoke", new Type[] { typeof(T), typeof(T) }),
                                   null);

                // Store the intermediate back into inoutvec
                generator.Emit(OpCodes.Stobj, typeof(T));

                // Increment the loop count
                generator.Emit(OpCodes.Ldloc_0);
                generator.Emit(OpCodes.Ldc_I4_1);
                generator.Emit(OpCodes.Add);
                generator.Emit(OpCodes.Stloc_0);

                // Increment invec by the size of T
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Sizeof, typeof(T));
                generator.Emit(OpCodes.Add);
                generator.Emit(OpCodes.Starg, 1);

                // Increment inoutvec by the size of T
                generator.Emit(OpCodes.Ldarg_2);
                generator.Emit(OpCodes.Sizeof, typeof(T));
                generator.Emit(OpCodes.Add);
                generator.Emit(OpCodes.Starg, 2);

                // Jump to the beginning of the loop
                generator.Emit(OpCodes.Br, loopStart);

                // End of our function
                generator.MarkLabel(loopDone);
                generator.Emit(OpCodes.Ret);
            }

            // Return a delegate to call the mpiDelegateMethod
            return((MPIDelegate)mpiDelegateMethod.CreateDelegate(typeof(MPIDelegate), op));
        }
Example #18
0
        /// <summary>
        /// Determine the predefined <c>MPI_Op</c> that is associated with
        /// this reduction operation. If no such <c>MPI_Op</c> exists,
        /// returns <see cref="Unsafe.MPI_OP_NULL"/>.
        /// </summary>
        public static MPI_Op GetPredefinedOperation(ReductionOperation <T> op)
        {
            // Predefined reduction operations with no representation in C#
            //   MPI_LXOR: There is no equivalent operator in C# or C++
            //   MPI_MAXLOC: We don't permit the data type used in reduction to differ
            //               from the type used in reduction.
            //   MPI_MINLOC: We don't permit the data type used in reduction to differ
            //               from the type used in reduction.

            // Min/max
            if (Kind == DatatypeKind.CInteger ||
                Kind == DatatypeKind.FortranInteger ||
                Kind == DatatypeKind.FloatingPoint)
            {
                if (op == min)
                {
                    return(Unsafe.MPI_MIN);
                }
                if (op == max)
                {
                    return(Unsafe.MPI_MAX);
                }
            }

            // Product/sum
            if (Kind == DatatypeKind.CInteger ||
                Kind == DatatypeKind.FortranInteger ||
                Kind == DatatypeKind.FloatingPoint ||
                Kind == DatatypeKind.Complex)
            {
                if (op == add)
                {
                    return(Unsafe.MPI_SUM);
                }
                if (op == multiply)
                {
                    return(Unsafe.MPI_PROD);
                }
            }

            // Logical and/or/xor
            if (Kind == DatatypeKind.CInteger ||
                Kind == DatatypeKind.Logical)
            {
                if (op == logicalAnd)
                {
                    return(Unsafe.MPI_LAND);
                }
                if (op == logicalOr)
                {
                    return(Unsafe.MPI_LOR);
                }
            }

            // Bitwise and/or/xor
            if (Kind == DatatypeKind.CInteger ||
                Kind == DatatypeKind.FortranInteger ||
                Kind == DatatypeKind.Byte)
            {
                if (op == bitwiseAnd)
                {
                    return(Unsafe.MPI_BAND);
                }
                if (op == bitwiseOr)
                {
                    return(Unsafe.MPI_BOR);
                }
                if (op == exclusiveOr)
                {
                    return(Unsafe.MPI_BXOR);
                }
            }

            return(Unsafe.MPI_OP_NULL);
        }
 public ReductionOperationView(ReductionOperation content)
   : this() {
   Content = content;
 }
Example #20
0
 void Aliencommunicator.Reduce <T> (int facet, T[] inValues, ReductionOperation <T> op, int root, ref T[] outValues)
 {
     this.RootCommunicator.Send <AliencommunicatorOperation>(AliencommunicatorOperation.REDUCE, 0, TAG_SEND_OPERATION + 2);
     alien_communicator.Reduce <T> (facet, inValues, op, root, ref outValues);
 }