:
.., . -01
.., . -02
.., . -02
.., ...,.
..
:
..-..,
. ..
, 2006
MPI. MPI , .
1. , MPI.
2.
3. π
4. .
5. .
6. .
7. .
8. .
9. .
MPI
MS Windows 9x/NT/XP
, . / /IP.
. /. , . MPICH: mpich.nt.1.2.5.exe (5 404 672 ). .
. . mpd.exe . Ctrl+Shift+Esc mpd.exe. , . .
, . MPIConfig.exe. ( : MPICH->mpd->MPICH Configuration tool. %PROGRAMFILES%\MPICH\mpd\bin\MPIConfig.exe).
1) , .
Show configuration, , , mpd .
2) , . , .. .
|
|
Apply. , . . .
, .
. hello.exe, 1. , hello.exe ( .2). ! NT , Microsoft Visual C++ 6.0 gcc win32.
, 2 :
: mpirun.exe. Ÿ :
#> mpirun np < > -logon ////cpi.exe
hello.exe:
%PROGRAMFILES%\MPICH\mpd\bin> mpirun -np 2 -logon \\12izlab2\mpi\hello.exe
Mpd needs an account to launch processes with:
account (domain\user): admin
password:
Hello world from process 1 of 2 at 11izlab2.
Hello world from process 0 of 2 at 12izlab2.
guiMPIRun.exe ( , MPICH) - .
, , . login . login. , . pwdfile < >. , , . , , .. .
. , Always prompt for password, , Advanced Options.
, :
1. .., .. . .: -, 2002.
2. . .
http://parallel.ru/tech/tech_dev/antonov.pdf
3. . . MPI
http://parallel.ru/tech/tech_dev/MPIcourse/
I
http://parallel.ru/tech/tech_dev/mpi.html
MPI-1.1 ( )
http://parallel.ru/docs/Parallel/mpi1.1/mpi-report.html
4. .. MPI
http://parallel.ru/vvv/mpi.html
MPICH official page
http.//www-unix.mcs.anl.gov/mpi/mpich/
MPI:The Complete Reference
http://www.netlib.org/utk/papers/mpi-book/mpi-book/html
|
|
1
, MPI
1.
MPICH. MS Visual C++ 6.0 .
2.
1. , ?
2. ?
3. ?
4. MPI Hello world.
5. .
6. mpich.lib mpi.h?
7. , , MPI .
8. Release Debug ?
9. SDK MPICH?
3.
"Hello world" MPI
"Hello world" . , .
MPI:
MPI_Init | MPI |
MPI_Comm_size | |
MPI_Comm_rank | |
MPI_Get_processor_name | , |
MPI_Finalize | MPI |
MS Visual C++
4.
, Microsoft Visual ++ 6.0.
.
FileÞNew Projects Win32 console application. (hello), .
Empty Project.
. FileÞNew C++ Source File hello.
.
mpi.h mpich.lib
(Alt+F7), C/C++, Preprocessor, Additionals include directories, include . %PROGRAMFILES%\mpich\sdk\include\.
Link, Object/library modules mpich.lib. MPI .
, , Input. Additional library path: *.lib MPICH. : %PROGRAMFILES%\mpich\sdk\lib
. F7. , Build :
--------------------Configuration: hello - Win32 Debug--------------------
Compiling...
hello.cpp
Linking...
hello.exe - 0 error(s), 0 warning(s)
.
hello.exe Debug , .
, /.
Release . ,
4.
// Hello world
#include <stdio.h>
#include mpi.h
int main(int argc, char * argv[])
{
int rank, size, resultlen;
char name[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Get_processor_name(name, &resultlen);
printf("Hello world from process %d of %d at %s\n", rank, size, name);
|
|
MPI_Finalize();
return 0;
};
5.
, . . , master/slave.
, MPI, MPI_COMM_WORLD .
.
2
1.
MPICH, MS Visual C++, C.
2.
1. ?
2. ?
3. , ?
4. ?
5. printf()?
6. MPI_Barrier()?
7. , MPI_Bcast()?
3.
, , .
4.
. MPI MPI_Bcast.
, , . . .
:
:
%PROGRAMFILES%\MPICH\mpd\bin> mpirun -np 2 -logon \\12izlab2\mpi\lab3.exe
Mpd needs an account to launch processes with:
account (domain\user): admin
password:
Enter a digit (0 or less to exit): 456
Process 0 (12izlab2.) got 456
Process 1 (11izlab2.) got 456
Enter a digit (0 or less to exit): 598
Process 0 (12izlab2.) got 598
Process 1 (11izlab2.) got 598
Enter a digit (0 or less to exit): 666
Process 0 (12izlab2.) got 666
Process 1 (11izlab2.) got 666
Enter a digit (0 or less to exit): -100
Process 0 (12izlab2.) got -100
Process 1 (11izlab2.) got -100
%PROGRAMFILES%\MPICH\mpd\bin>
5.
fflush(stdout) printf(). , . , , stdout , , , . fflush() stdout.
, , .. , . , MPI_Bcast() , .. , , . , MPI_Bcast() . , . , . ( ). , , , MPI_Barrier(comm). , . , , -. ( ) MPI_Bcast().
|
|
3
π
1.
MPICH. . π, .
2.
1. ?
2. ?
3. ( MPI) ?
4. π .
5. MPI_Reduce.
6. MPI_Wtime.
7. ?
8. -.
9.
π -.
4.
MPI. , π .
π : . : , . , , , . .. m ( m- ), . , m . n , , . n m. .. 4 , n 4. , m . (n/m ), (n 1 , n+1, 2 , ).
, :
MPI_Init | MPI |
MPI_Comm_size | |
MPI_Comm_rank | |
MPI_Get_processor_name | , |
MPI_Bcast | . |
MPI_Reduce | |
MPI_Wtime | , |
MPI_Finalize | MPI |
5.
2 : 'prog1.'
0 : 'prog2.'
3 : 'prog3.'
1 : 'prog4.'
(n): (0 ) 1024
: pi=3.1415927330626534, 0.0000000794728603
0.157488
(n): (0 ) 100000
: pi=3.1415926535981167, 0.0000000000083236
0.011448
(n): (0 ) 1000000
: pi=3.1415926535899033, 0.0000000000001101
0.100975
(n): (0 ) 10000000
: pi=3.1415926535896856, 0.0000000000001075
1.004657
(n): (0 ) 100000000
: pi=3.1415926535902168, 0.0000000000004237
9.993571
(n): (0 ) 0
6.
, , , startwtime = MPI_Wtime();. 01.01.2971. , endwtime = MPI_Wtime();. endwtime-startwtime .
|
|
sum , .. . MPI_Reduce() , mypi.
MPI_Reduce() , MPI_SUM.
, .
:
double PI25DT = 3.141592653589793238462643; //
fflush(stdout) printf().
:
MPI_Init(&argc,&argv); //
MPI_Comm_size(MPI_COMM_WORLD,&numprocs); //
MPI_Comm_rank(MPI_COMM_WORLD,&myid); //
MPI_Get_processor_name(processor_name,&namelen);//
4
1.
MPI. C. , MPI, .
2.
1. ?
2. ?
3. ( MPI) ?
4. π, .
5. MPI_ Reduce.
6. MPI_Wtime.
7. ?
8. -.
n : , , . . , .
. . , . . . ( ) . :
MPI_Send (, , MPI_CHAR, 1, 1, MPI_COMM_WORLD).
. . .
. .. :
MPI_Recv (, , MPI_CHAR, . , MPI_COMM_WORLD, & statuc);
MPI_Send (, , MPI_CHAR, ., ., MPI_COMM_WORLD);
.
MPI Recv (, , MPI_CHAR, . , 0, MPI_COMM_WOPLD & status);
: , .. MPI_Recv(), MPI_Send() , .. .
|
|
|
|
(1024 )
1 1024 0 0.0001242
1 1024 1 0.0018743
1 1024 2 0.0002536
1 3: 0.0035021
5
1.
MPICH . .
1. .
2. .
3. .
4. .
5. MPI_Allreduce()
6. ?
7. ?
8. ?
9. ?
10. MPI_WTime ?
11. - ?
3.
. .
4.
1212 , . , , :
for (i,j) xnew [i][ j] = (x[ i + 1][ j] + x[ i- I][j] + x[i][j + 1] + [i][ j - 1]/4;
for(i,j) x [i][j ]= xnew [i][j].
:
X [0 ][ j ], x[ n 1] [j], x [ i ][ 0], x [i ] [n - 1].
¼ , . .
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
3 3 3 3 3 3 3 3 3 3
3 3 3 3 3 3 3 3 3 3
2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2
2 2 2 2 2 2 2 2 2 2
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
, 1 . 100 . MPI_Allreduce() MPI_SUM.
5.
|
6.
At iteration 1, diff is 3. 791438e + 000
At iteration 2, diff is 3. 948557e + 000
At iteration 3, diff is 3. 324536e + 000
At iteration 4, diff is 3. 014272e + 000
At iteration 5, diff is 3. 266808e + 001
At iteration 6, diff is 3. 992270e + 001
At iteration 7, diff is 3. 063208e + 001
At iteration 8, diff is 3. 354581e + 001
At iteration 9, diff is 3. 796424e + 001
At iteration 10, diff is 3. 345620e + 001
...
At iteration 91, diff is 1. 077600e + 002
At iteration 92, diff is 1. 033949e + 002
At iteration 93, diff is 9. 920652e + 003
Final solution is
-1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000
-1.00000 1.00000 1.00000
3.000000 0.892898 0.065635 -0.299648 -0.470180 -0.539828 -0.539828 -0.470180
0.892898 3.00000
3.000000 1.505402 0.668228 -0.043031 -0.151248 -0.043031 0.204468 0.668228
1.505402 3.000000
2.000000 1.459421 0.895371 0.489475 0.241411 0.125389 0.125386 0.241411 0.489475 0.895371 1.459421 2.000000
2.000000 1.435428 0.961518 0.612675 0.389030 0.280790 0.280790 0.389030 0.612675 0.961518 1.435428 2.000000
2.000000 1.318993 0.899183 0.605903 0.415499 0.321700 0.415499 0.605903 0.899183
1.318993 2.000000
1.0000000 0.939427 0.706611 0.491070 0.339122 0.262020 0.262020 0.33122 0.491070 0.706611 0.939427 1.000000
1.000000 0.730175 0.493062 0.307470 0.181674 0.118464 0.118464 0.181674
0.307470 0.493062 0.730175 1.000000
1.000000 0.486443 0.224600 0.059331 0.044069 0.094514 -0.094514 -0.044069 0.059331 0.224600 0.486443 1.000000
0.000000 -0.010469 -0.143252 -0.254610 -0.327503 -0.363090 -0.363090 -0.327503 -0.254610 -0.143252 -0.010469 0.000000
0.000000 0.386115 -0.534537 -0.609828 -0.670933 0.670933 -0.651626 -0.609828 -0.534537 -0.386115 0.000000
-1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000
MPI. . Message Passing Interface ( ). MPI , , . MPI 1.1 1998 .
MPI . 125 .
MIMD (Multiple Instruction Multiple Data), SPMD- (Single Program Multiple Data).
MPI- . . . .
. . , , . MPI_COMM_WORLD, , MPI-.
. , . . n 0 n-1.
.
. , , , , .
() . .
MPI . MPI_SUCCESS, .
MPI
MPI_Init(*argc,*argv) | MPI . MPI | , |
MPI_Comm_size(comm,*size) | , | |
MPI_Comm_rank(comm,*rank) | , | |
MPI_Abort(comm,errorcode) | MPI | , |
MPI_Get_processor_name(*name,*resultlength) | , | |
MPI_Initialized (*flag) | MPI | (1-, 0 ) |
MPI_Wtime () | , | |
MPI_Finalize () | MPI . MPI . MPI ( MPI_Init()) |
-
MPI_Send(buffer,count,type,dest,tag,comm) | , , , , , | |
MPI_Isend(buffer,count,type,dest,tag,comm,request) | ( ) | ->>-, . |
MPI_Ssend (*buf,count,datatype,dest,tag,comm,ierr) | ||
MPI_Bsend (*buf,count,datatype,dest,tag,comm) | ->>- | |
MPI_Recv(buffer,count,type,source,tag,comm,status) | ->>- | |
MPI_Irecv(buffer,count,type,source,tag,comm,request) | ( ) | ->>- |
MPI_Rsend (*buf,count,datatype,dest,tag,comm) | . | ->>- |
MPI_Buffer_attach (*buffer,size) | , | |
MPI_Buffer_detach (*buffer,size) | -->>-- | |
MPI_Sendrecv (*sendbuf,sendcount,sendtype,dest,sendtag, *recvbuf, recvcount, recvtype, source, recvtag, comm,*status) | . . | , . , . ., , , . |
MPI_Probe (source,tag,comm,*status) | . . | , , , |
MPI_Barrier (comm) | . | |
MPI_Bcast (*buffer,count,datatype,root,comm) | . | , , , -, |
MPI_Scatter (*sendbuf,sendcnt,sendtype,*recvbuf,...... recvcnt,recvtype,root,comm) | , , , , , . | |
MPI_Gather (*sendbuf,sendcnt,sendtype,*recvbuf,...... recvcount,recvtype,root,comm) | . | , , , , , . |
MPI_Reduce (*sendbuf,*recvbuf,count,datatype,op,root,comm) | , , , , , . | |
MPI_Allreduce (*sendbuf,*recvbuf,count,datatype,op,comm) | , , , , , . |
MPI | |
MPI_CHAR | signed char |
MPI_SHORT | signed short int |
MPI_INT | signed int |
MPI_LONG | signed long int |
MPI_UNSIGNED_CHAR | unsigned char |
MPI_UNSIGNED_SHORT | unsigned short |
MPI_UNSIGNED | unsigned int |
MPI_UNSIGNED_LONG | unsigned long int |
MPI_FLOAT | float |
MPI_DOUBLE | double |
MPI_LONG_DOUBLE | long double |
MPI_BYTE | 8 |
MPI_PACKED | , MPI_Pack() |
(buffer) | *char | , . malloc |
( Count) | Unsigned long | . . |
(type) | MPI_TYPE | . . |
(destination) | Unsigned long | -. MPI_ANY_SOURCE |
(tag) | Unsigned long | . , . MPI_ANY_TAG |
(comm) | Unsigned long | . MPI_COMM_WORLD |
(status) | Struct MPI_STATUS | , . mpi.h |
(request) | Struct MPI_REQUEST | . . |