MPI.NET C# 2 2009 1 20
MPI.NET MPI.NET C#
MPI.NET C# MPI MPI.NET 1 1 MPI.NET C# Hello World
MPI.NET.NET Framework.NET C# API
C# Microsoft.NET java.net (Visual Basic.NET Visual C++)
C# class Helloworld // { public static void Main() // { // System.Console.Write( Hello World\n ); } }
MPI Message Passing Interface MPI MPI-1 MPI-2 2 MPI.NET MPICH MPICH2 LAM/MPI MS-MPI Ver. 2 1 2 1 2.NET C# C, C++, fortran
MPI 1 1 ID
1 if else
C# Visual Studio 2008 Visual C# 2008 Express Edition.NET.NET Framework 3.5 MPI.NET MPI.NET SDK 1.0 OS Windows HPC Server 2008 HPC Pack 2008 SDK Microsoft Compute Cluster Server 2003 Microsoft Compute Cluster Pack SDK
MPI.NET 1 1 Send Receive ImmediateSend ImmediateReceive Barrier Gather Broadcast Reduce
Send Receive ImmediateSend ImmediateReceive
Send public void Send<T>(value, dest, tag) value dest tag int if (comm.rank == 0) { string value = Windows ; comm.send(value, 1, 9); }
Receive public T Receive<T>(source, tag) source tag int if (comm.rank == 0) { string value = Windows ; comm.send(value, 1, 9); } else if(comm.rank == 1) { string msg = comm.receive<string>(0, 9); } Console.Write(msg);
(1/2) 1. Visual Studio 2008 2. -> ->
(2/2) 3. 4. Message Passing Interface
1 1 (1/2) HelloWorld 0 1 using System; using MPI; // MPI class Helloworld { static void Main(string[] args) { // MPI using (new MPI.Environment(ref args)) { MPI } } }
1 1 (2/2) // Intracommunicator comm = Communicator.world; int tag = 9; // if (comm.rank == 0) { comm.send( HelloWorld, 1, tag); // 1 } else if(comm.rank == 1) { string msg = comm.receive<string>(0, tag); // 0 Console.Write(msg); }
& Shift + F6 -> PowerShell > job submit /scheduler:( ) /numcores:( ) /workdir:( ) mpiexec ( )
C mpich (1/2) #include <stdio.h> #include <string.h> #include <mpi.h> // using MPI int main(int argc, char *argv[]) { char msg[20]; // int rank; // int tag = 9; // new MPI.Environment(ref args) MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank);
C mpich (2/2) if (rank == 0) { sprintf(msg, HelloWorld ); MPI_Send(msg, strlen(msg), MPI_CHAR, 1, tag, MPI_COMM_WORLD); } else if(rank == 1) { MPI_Status status; MPI_Recv(msg, 20, MPI_CHAR, 0, tag, MPI_COMM_WORLD, &status); } } printf( %s\n, msg); MPI_Finalize(); return 0;
MPI.NET mpich MPI.NET comm.send(value, dest, tag) 3 4 mpich MPI_Send(void *msg, int count, MPI_Datatype datatype, int dest, int tag, MPI_COMM comm) msg count MPI_Datatype dest tag comm 6
for(i=0; i<num; i++){ comm.send( HelloWorld, i, tag); } MPI one-to-all, all-to-one, all-to-all
: one to all public void Broadcast<T>(ref T value, root) 1 ref T value root root
: all to one public T[] Gather<T>(value, root) value root root
: Reduction( ) public T Reduce<T>(value, Operation, root) value Opration root root
(1/3) -1 1 = 4
(2/3) 1. 2. 0 Reduce 3. 0 Reduce 4. 0 http://www.osl.iu.edu/research/mpi.net/
(3/3) Random random = new Random(comm.Rank); // int num = 10000; // int count = 0; // for (int i = 0; i < num; ++i) { double x = (random.nextdouble() - 0.5) * 2; double y = (random.nextdouble() - 0.5) * 2; if (x * x + y * y <= 1.0) ++ count; } int total = comm.reduce(count, Operation<int>.Add, 0); if (comm.rank == 0) Pi = 4*(double) total/(comm.size*(double)num));
C# MPI.NET MPI.NET MPI.NET C#
MPI.NET( ) http://www.osl.iu.edu/research/mpi.net/ MPI.NET http://www.osl.iu.edu/research/mpi.net/document ation/reference/current/index.html