6-amaliy mashg’ulot Faxriddinov Umid 202-guruh talabasi int mpi isend funksiyasi


Download 20.41 Kb.
bet3/4
Sana03.04.2023
Hajmi20.41 Kb.
#1322364
1   2   3   4
Bog'liq
202 Faxriddinov Umid

MPI_Waitall funksiyasi
MPI_Waitall – barcha berilgan MPI so'rovlarining bajarilishini kutadi
int MPI_Waitall(int count ,MPI_so'rovlar massivi [] , MPI_statuslar_holatlari_massivi []);
Parametrlar:
count –ro'yxat uzunligi (butun)
so'rovlar_massivi – so'rovlar tutqichlari massivi (dastaklar massivi)
MPI_statuslar_holatlari_massivi [] – holat obyektlari massivi (Statuslar massivi). MPI_STATUSES_IGNORE bo'lishi mumkin .
The following sample code illustrates MPI_Waitall.
MPI_Waitall funksiyasiga misollar:
#include "mpi.h"
#include
int main(int argc, char *argv[])
{
int rank, size;
int i;
int buffer[400];
MPI_Request request[4];
MPI_Status status[4];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size != 4)
{
printf("4 ta jarayon bilan ishga tushirish.\n");fflush(stdout);
MPI_Finalize();
return 1;
}
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
for (i=0; ibuffer[i] = i/100;
for (i=0; i{
MPI_Isend(&buffer[i*100], 100, MPI_INT, i+1, 123, MPI_COMM_WORLD, &request[i]);
}
MPI_Waitall(size-1, request, status);
}
else
{
MPI_Recv(buffer, 100, MPI_INT, 0, 123, MPI_COMM_WORLD, &status[0]);
printf("%d: buffer[0] = %d\n", rank, buffer[0]);fflush(stdout);
}
MPI_Finalize();
return 0;
}
MPI_Test funksiyasi
MPI_Test–so'rovni bajarish uchun testlar
int MPI_Test (MPI_Request * requess, int *flag,
MPI_Status * holati
);
Parametrlar
requess – MPI so'rovi (dastur)
flag – Agar operatsiya tugallangan bo'lsa, rost (mantiqiy)
status – holat obyekti (Status). MPI_STATUS_IGNORE bo'lishi mumkin

MPI_Test funksiyasiga msol:
#include "mpi.h"
#include
int main(int argc, char *argv[])
{
int myid, numprocs, left, right, flag=0;
int buffer[10], buffer2[10];
MPI_Request request;
MPI_Status status;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myid);
right = (myid + 1) % numprocs;
left = myid - 1;
if (left < 0)
left = numprocs - 1;
MPI_Irecv(buffer, 10, MPI_INT, left, 123, MPI_COMM_WORLD, &request);
MPI_Send(buffer2, 10, MPI_INT, right, 123, MPI_COMM_WORLD);
MPI_Test(&request, &flag, &status);
while (!flag)
{
MPI_Test(&request, &flag, &status);
}
MPI_Finalize();
return 0;
}


Download 20.41 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling