MPI.NET C# 2 2009 2 27
MPI MPI MPI.NET C# MPI Version2
MPI (Message Passing Interface) MPI MPI Version 1 1994 1 1 1
1 ID MPI MPI_Send MPI_Recv if(rank == 0){ // 0 MPI_Send(); } else if(rank == 1){ // 1 MPI_Recv(); } else if(rank == 2){
MPI Version2 MPI-1 1997 MPI Version2 MPI Version 1 ( ) 2
MPI MPI MPI MPI.NET MPICH MPICH2 LAM/MPI MS-MPI Ver. 2 1 2 1 2.NET C# C, C++, fortran MPI.NET C#
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 ID
MPI 1. Visual Studio 2. 3. PowerShell MS-DOS
(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);
Tag public T Receive<T>(source, tag) source tag int
1 HelloWorld Visual Studio Hello World Hello World
(1/2) Visual Studio 2008 -> -> ->
(2/2) 3. 4. Message Passing Interface
HelloWorld using System; using MPI; class MPIHello { static void Main(string[] args) { // MPI.Environment ( MPI ) using (new MPI.Environment(ref args)) { Console.WriteLine("Hello World from rank " + Communicator.world.Rank + " (running on " + MPI.Environment.ProcessorName + ")"); } } }
+ 5. -> 6. C:\Documents and Settings\ \My Documents \Visual Studio 2008\Projects\ \ \bin\debug
+ 7-1. MS-DOS > mpiexec -np ( ) 7-2. PowerShell > job submit /scheduler:( ) /numcores:( ) /workdir:( ) /stdout:( ) mpiexec ( )
Hello World from rank (running on )
2 1 1 2 Send Receive ->
Point-to-Point Communication(1/2) HelloWorld 0 1 using System; using MPI; // MPI class PtoPHello { static void Main(string[] args) { // MPI using (new MPI.Environment(ref args)) { } } }
Point-to-Point Communication(2/2) // Intracommunicator comm = Communicator.world; int tag = 9; // if (comm.rank == 0) { comm.send( Hello World, 1, tag); // 1 } else if(comm.rank == 1) { string msg = comm.receive<string>(0, tag); // 0 Console.WriteLine(msg + " from rank " + comm.rank); }
Hello World from rank 1
for(i=0; i<num; i++){ comm.send( Hello World, 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
3 Broadcast Reduce ->
Collective Communication(1/2) using System; using MPI; // MPI class Collective { // public static int AddInts(int x, int y) { return x + y; } } static void Main(string[] args) { // MPI using (new MPI.Environment(ref args)) { } }
Collective Communication(2/2) Intracommunicator comm = Communicator.world; int msg = 0; if (comm.rank == 0) msg = 5; comm.broadcast(ref msg, 0); // 0 msg msg = comm.rank * msg; // * 5 Console.WriteLine(msg + from rank + comm.rank); // int sum = comm.reduce(msg, AddInts, 0); // 0 int sum2 = comm.reduce(msg, Operation<int>.Add, 0); // 0 int max = comm.reduce(msg, Operation<int>.Max, 0); // 0 int min = comm.reduce(msg, Operation<int>.Min, 0); // 0 if (comm.rank == 0) Console.WriteLine( Sum : + sum + Sum : + sum2 + Max : + max + Min : + min); // Reduce
5
MPI Version 2 MPI.NET
MPI Version 1 I/O 1 MPI_Gather 1
MPI Version 1 I/O 1 2 N I/O
MPI Version 2 I/O open close seek read write MPI
1. MPI_FILE 2. MPI_FILE_open 3. MPI_FILE_set_view 4. MPI_FILE_read/MPI_FILE_write 5. MPI_FILE_close
MPI Version 1 -np MPI Version 2 /
Broadcast
(1/2)
(2/2) N 3 1
MPI C# MPI.NET MPI version2
MPI.NET( ) http://www.osl.iu.edu/research/mpi.net/ MPI-2 Gropp, Lusk, Thakur ( ) 2002 MPI Version 2 http://www.mpi-forum.org/docs/mpi-20-html/mpi2-report.html http://compview.titech.ac.jp/members/endot/ adv-app-hpc/ 7