.


:




:

































 

 

 

 


.




- . . MPI_Group , . , , : MPI_GROUP_EMPTY , , ; MPI_GROUP_NULL , . MPI, - .

, - (, , ), "" : , , .

.

MPI , . . MPI_Comm_rank . , . MPI . MPI_COMM_WORLD, . . MPI_Comm_rank , . MPI_Comm_size . , 0 , . -, . MPI-

var p:pointer;

rank,size:integer;

begin

//

p:=nil;

rank:=0;

MPI_Init(@rank,p);

MPI_Comm_rank(MPI_COMM_WORLD,@rank);

MPI_Comm_size(MPI_COMM_WORLD,@size);

if rank=0 then begin

//

end else begin

//

end;

MPI_Finalize();

end.

3. 2*cos(x) ң [0,1] қ ң.

double f(double x)

{return 2*cos(x);}

int main(intargc,char **argv)

{

intsize,rank;

MPI_Status status;

MPI_Init(&argc,&argv);

MPI_Comm_rank(MPI_COMM_WORLD,&rank);

MPI_Comm_size(MPI_COMM_WORLD,&size);

float h=0.05,a=0,b=1,s=0.0;

for(inti=rank; a+h*(i+1)<b+h; i+=size)

{ s+=h*f(a+h*(i+1)); }

if(rank!=0)

{ MPI_Send(&s,1,MPI_FLOAT,0,1,MPI_COMM_WORLD);

}

if(rank==0)

{ float r;

MPI_Recv(&r,1,MPI_FLOAT,1,1,MPI_COMM_WORLD,&status);

s+=r;

printf("s=%f\n ",s);

}

}

1. . Ү. .

. , -- . , .

, , . , , . 1, s , . :T1 = TS + .

, N V , / N, :T2=TS+ Tp/N.

, , , , := }/2 = (Ts + Tp) / (Ts + Tp/N) = 1/(S + P/N),

S= Ts / (Ts + Tp) P= Tp / (Ts + Tp) (S+ = 1). ( ) . 2.5. .

, () - . , . , .

2.MPI ә . ү ? Қ .

MPI-, MPI- mpi.h, C #include<mpi.h> .

- , . MPI , , .

/ , C- MPI_Datatype. MPI MPI_Datatype, :

MPI_CHAR-

MPI_SHORT-

MPI_INT-

MPI_LONG-

MPI_UNSIGNED_CHAR-

MPI_UNSIGNED_SHORT-

MPI_UNSIGNED-

MPI_UNSIGNED_LONG-

MPI_FLOAT-

MPI_DOUBLE-

MPI_LONG_DOUBLE-

MPI_BYTE=

. MPI :

: . count , oldtype ( ). - - ;

: , . . - , ;

H-: , ;

: ;

;

H-: , ;

: . , MPI, .

. MPI_Type_contiguous, , count , oldtype. , (oldtype) {(int,0),(double,8)}, MPI_Type_contiguous(2, oldtype, &newtype); newtype {(int,0),(double,8),(int,16),(double,24)}.

 

 

3. ққ ң.

Prostoe.

int main(intargc,char **argv)

{

intsize,rank;

MPI_Status status;

MPI_Init(&argc,&argv);

MPI_Comm_rank(MPI_COMM_WORLD,&rank);

MPI_Comm_size(MPI_COMM_WORLD,&size);

int k=127,p,l=0,x1,l1,l2=0,itog=0,i; // k - issleduemoechislo

p=k/(size-1);

if (rank!=size-1) // schitautvseprocessy, kromeposlednego

// metodpereboradelitelei

{ for (i=rank*p+1; i<=(rank+1)*p; i++) { x1=k/i; if (x1*i==k) {l++;} }

MPI_Send(&l,1,MPI_INT,size-1,1,MPI_COMM_WORLD);}

else

{ for (i=0; i<size-1; i++) // poslednii process vsesobiraet

{ MPI_Recv(&l1,1,MPI_INT,i,1,MPI_COMM_WORLD, &status); itog+=l1; }

for (i=(size-1)*p+1; i<=k; i++) { x1=k/i; if (x1*i==k) {l2++;} } itog+=l2;

if (itog>2) {printf("Ne yavlyaetsyaprostym\n"); } else { printf("Prostoe\n"); } }

MPI_Finalize();}

 

 

1.Қ . қ ө.

. . : , , . , , . . :

MIMD (MultipleInstructionMultipleData - ). MIMD N , N N . .

SIMD (SingleInstructionMultipleData - ). SIMD N , N . . , , .

, , , , . .. - . , , , . : , , flash-. , . . , .

- . , , . , .

2.MPI_CART_COORDS() қ .

:intMPI_Card_coords(MPI_Commcomm,intrank,intndims,int *coords), - comm , - rank - , , - ndims - , - coords- .

MPI_Cart_coords(cartcomm, rank, 3, coords);

 

3.2 өң 2-ө ә.

1. ә қ ә. .

. (.. , , , ..). (.. , , , ..). : (trival), (functional) . . , , .

, , . -. , , .





:


: 2016-07-29; !; : 704 |


:

:

- , 20 40 . - .
==> ...

1853 - | 1806 -


© 2015-2024 lektsii.org - -

: 0.028 .