in MPI/DatatypeCache.cs [194:278]
private static Dictionary<Type, MPI_Datatype> BuiltinDatatypes()
{
Dictionary<Type, MPI_Datatype> builtins = new Dictionary<Type, MPI_Datatype>();
// Integral types
builtins.Add(typeof(System.SByte), Unsafe.MPI_SIGNED_CHAR);
builtins.Add(typeof(System.Byte), Unsafe.MPI_BYTE);
builtins.Add(typeof(System.Int16), Unsafe.MPI_SHORT);
builtins.Add(typeof(System.UInt16), Unsafe.MPI_UNSIGNED_SHORT);
builtins.Add(typeof(System.Int32), Unsafe.MPI_INT);
builtins.Add(typeof(System.UInt32), Unsafe.MPI_UNSIGNED);
builtins.Add(typeof(System.Int64), Unsafe.MPI_LONG_LONG);
builtins.Add(typeof(System.UInt64), Unsafe.MPI_UNSIGNED_LONG_LONG);
// Floating-point types
builtins.Add(typeof(System.Single), Unsafe.MPI_FLOAT);
builtins.Add(typeof(System.Double), Unsafe.MPI_DOUBLE);
// Character type
builtins.Add(typeof(System.Char), Unsafe.MPI_WCHAR);
// Determine whether we can use MPI_LONG and MPI_UNSIGNED_LONG for
// System.IntPtr or System.UIntPtr.
IntPtr mpiLongSize;
unsafe
{
int errorCode = Unsafe.MPI_Type_extent(Unsafe.MPI_LONG, out mpiLongSize);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
}
if (mpiLongSize.ToInt32() == Marshal.SizeOf(typeof(System.IntPtr)))
{
// Since the MPI datatype size for "long" is the same as
// for IntPtr and UIntPtr, use MPI's long and unsigned long
builtins.Add(typeof(IntPtr), Unsafe.MPI_LONG);
builtins.Add(typeof(UIntPtr), Unsafe.MPI_UNSIGNED_LONG);
}
else
{
// Build a derived datatype for IntPtr.
MPI_Datatype datatype;
unsafe
{
int errorCode = Unsafe.MPI_Type_contiguous(Marshal.SizeOf(typeof(System.IntPtr)), Unsafe.MPI_BYTE, out datatype);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
errorCode = Unsafe.MPI_Type_commit(ref datatype);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
}
builtins.Add(typeof(System.IntPtr), datatype);
// Build a derived datatype for UIntPtr.
unsafe
{
int errorCode = Unsafe.MPI_Type_contiguous(Marshal.SizeOf(typeof(System.UIntPtr)), Unsafe.MPI_BYTE, out datatype);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
errorCode = Unsafe.MPI_Type_commit(ref datatype);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
}
builtins.Add(typeof(System.UIntPtr), datatype);
}
// Build a derived datatype for System.Decimal
MPI_Datatype decimalDatatype;
unsafe
{
int errorCode = Unsafe.MPI_Type_contiguous(Marshal
.SizeOf(typeof(System.Decimal)), Unsafe.MPI_BYTE, out decimalDatatype);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
errorCode = Unsafe.MPI_Type_commit(ref decimalDatatype);
if (errorCode != Unsafe.MPI_SUCCESS)
throw Environment.TranslateErrorIntoException(errorCode);
}
builtins.Add(typeof(System.Decimal), decimalDatatype);
// Packed data
builtins.Add(typeof(Packed), Unsafe.MPI_PACKED);
return builtins;
}