3-topshiriq



Download 2,33 Mb.
bet2/5
Sana02.07.2022
Hajmi2,33 Mb.
#730137
1   2   3   4   5
Bog'liq
3.4.5 topshiriq

4-TOPSHIRIQ
1. Ikkita jarayondan uchinchi jarayonga istalgan tipdagi bir xil teg orqali ma'lumot jo'nating va uni MPI_ANY_SOURCE ni ishlatgan holda qabul qiling. va uni ekranga chiqaring.Ma'lumot qaysi jarayondan qabul qilinganligini izohlang.

#include "mpi.h"


#include
using namespace std;
int main(int argc, char **argv)
{
int rank;
double a, b, c;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
a = 0.0; b = 0.0, c=0.0;
if (rank == 0) {
b=778.80;
MPI_Send(&b, 1, MPI_DOUBLE,2,7, MPI_COMM_WORLD);
}
if (rank == 1) {
a=378.876;
MPI_Send(&a, 1, MPI_DOUBLE,2,7, MPI_COMM_WORLD);
}
if (rank == 2) {
MPI_Recv(&c, 1, MPI_DOUBLE, MPI_ANY_SOURCE,7, MPI_COMM_WORLD,&status);

}
cout << " process " << rank << " a = " << a << " b = " << b << " c = "<< c<
MPI_Finalize();

2.Ikkita jarayondan uchinchi jarayonga bitta manzilga istalgan tipdagi va turli tegdagi ma'lumot jo'nating va uni MPI_ANY_TAG ni ishlatgan holda qabul qiling va ma'lumotni ekranga chiqaring.Ma'lumot qaysi jarayondan qabul qilinganligini izohlang.
#include "mpi.h"
#include
using namespace std;
int main(int argc, char **argv)
{
int rank;
float a, b, c;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
a = 0.0; b = 0.0, c=0.0;
if (rank == 0) {
b=4.87;
MPI_Send(&b,1,MPI_FLOAT,2,5,MPI_COMM_WORLD);
}
if (rank == 1) {
a=3.906;
MPI_Send(&a,1,MPI_FLOAT,2,4,MPI_COMM_WORLD);
}
if (rank == 2) {
MPI_Recv(&c,1,MPI_FLOAT,0,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
MPI_Recv(&c,1,MPI_FLOAT,1,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
}
cout << " process " << rank << " \ta = " << a << " \tb = " << b <<" \tc="<MPI_Finalize();
}

3.Bir jarayon orqali bir nechta jarayonlardan MPI_ANY_SOURCE va MPI_ANY_TAG dan foydalangan holda xabarlar qabul qiling va natijani izohlang


#include "mpi.h"
#include
using namespace std;
int main(int argc, char **argv)
{
int rank;
int a, b, c, d;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
a = 0.0; b = 0.0, c=0.0, d=0.0;
if (rank == 0) {
a=8.0;
MPI_Send(&a, 1, MPI_INT, 3, 5, MPI_COMM_WORLD);
}
if (rank == 1) {
b=6.0;
MPI_Send(&b, 1, MPI_INT, 3, 6, MPI_COMM_WORLD);
}
if (rank == 2) {
c=97.0;
MPI_Send(&c, 1, MPI_INT, 3, 7, MPI_COMM_WORLD);
}
if (rank == 3) {
MPI_Recv(&d, 1, MPI_INT, MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
MPI_Recv(&d, 1, MPI_INT, MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
MPI_Recv(&d, 1, MPI_INT, MPI_ANY_SOURCE,MPI_ANY_TAG,MPI_COMM_WORLD,&status);
}
cout << " process " << rank << " \ta = " << a << " \tb = " << b <<" \tc = " <<
c <<"\td= " << d <MPI_Finalize();
}

4. Bir jarayondan ikkinchi jarayonga xabar jo'nating va qabul qilingan xabar uzunligini MPI_Get_Count funksiyasi orqali aniqlang.
#include "mpi.h"
#include
using namespace std;
int main(int argc, char**argv)
{
int rank;
float a; MPI_Status status;
int count=0;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
a = 0.0;
if (rank == 1) {
a = 1.0;
MPI_Send(&a, 1, MPI_FLOAT, 2, 5, MPI_COMM_WORLD);
}
if (rank == 2) {
MPI_Recv(&a, 1, MPI_FLOAT, 1, 5, MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_INT,&count);
}
MPI_Get_count(&status, MPI_INT, &count);
cout << " process " << rank << " a = " << a <<" elementlar soni= "<MPI_Finalize();
}

5.MPI_Probe ning ikki holatda ishlatilishi bo’yicha dastur tuzing va uni tushuntirib bering


1-usul.
#include "mpi.h"
#include
using namespace std;
int main(int argc, char**argv)
{
int rank; float a, b, c;
MPI_Status status; int buf_count; char*buf;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
a = 0.0; b = 0.0; c = 0.0;
if (rank == 0) {
b = 3;
MPI_Send(&b, 1, MPI_INT, 1, 4, MPI_COMM_WORLD);
MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
MPI_Get_count(&status, MPI_INT, &buf_count);
MPI_Recv(&c, buf_count, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
MPI_Recv(&a, 1, MPI_INT, 1, 5, MPI_COMM_WORLD, &status);
}
if (rank == 1) {
a = 2;
MPI_Recv(&b, 1, MPI_INT, 0, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
MPI_Send(&a, 1, MPI_FLOAT, 0, 5, MPI_COMM_WORLD);
}
if (rank == 2) {
c = 7;
MPI_Send(&c, 2, MPI_FLOAT, 0, 3, MPI_COMM_WORLD);

}
cout << " process " << rank << " a = " << a << " b = " << b << " c = " << c << endl;


MPI_Finalize();
return 0;
}

2-holat
#include "mpi.h"
#include
#include
using namespace std;
int main(int argc, char**argv) {
int rank; float a, b, c; MPI_Status status;
int d;
double f;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
a = 0.0; b = 0.0; c = 0.0; d = 0.0; f = 0.0;
if (rank == 0) {
b = 1.0;
c = 3.0;
MPI_Send(&b, 1, MPI_INT, 1, 5, MPI_COMM_WORLD);
MPI_Send(&c, 1, MPI_INT, 2, 5, MPI_COMM_WORLD);

for (int i = 0; i<3; i++) {


MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
switch (status.MPI_TAG) {
case 1:
MPI_Recv(&a, 1,MPI_DOUBLE, 2, 1, MPI_COMM_WORLD, &status);
break;
case 2:
MPI_Recv(&d, 1, MPI_INT, 2, 2, MPI_COMM_WORLD, &status);
break;
case 3:
MPI_Recv(&f, 1, MPI_FLOAT, 1, 3, MPI_COMM_WORLD, &status); break;
}
}
MPI_Recv(&a, 1, MPI_FLOAT, 1, 3, MPI_COMM_WORLD, &status);
MPI_Recv(&d, 1, MPI_INT, 2, 2, MPI_COMM_WORLD, &status);
MPI_Recv(&f, 1, MPI_DOUBLE, 2, 1, MPI_COMM_WORLD, &status);
}
if (rank == 1) {
a = 2.702;
MPI_Recv(&b, 1, MPI_FLOAT, 0, 5, MPI_COMM_WORLD, &status);
MPI_Send(&a, 1, MPI_FLOAT, 0, 3, MPI_COMM_WORLD);
}
if (rank == 2) {
d = 4.0;
f = 555.0;
MPI_Recv(&c, 1, MPI_FLOAT, 0, 5, MPI_COMM_WORLD, &status);
MPI_Send(&d, 1, MPI_INT, 0, 2, MPI_COMM_WORLD);
MPI_Send(&f, 1, MPI_DOUBLE, 0, 1, MPI_COMM_WORLD);
}
cout << " process " << rank << " a = " << a << " b = " << b << " c = " << c << " d = " << d << " f = " << f << endl;
MPI_Finalize();
}

6)Uchta jarayonda uch xil matematik misol ishlang va natijalarni 4- jarayonga jo’nating va jarayonlarning ishlash vaqtilarini aniqlang va bir biri bilan taqqoslab xulosa chiqaring.

#include "mpi.h"


#include
#include
using namespace std;
int main(int argc,char**argv)
{
int rank;
float a,b,c;MPI_Status status;
double t1, t2,T;
double MPI_Wtick;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
t1 = MPI_Wtime();
a=0,0; b=0.0; c=0,0;
if(rank==1){
a=(3*7)/2;
MPI_Send(&a,1,MPI_FLOAT,4,1,MPI_COMM_WORLD);
}
if(rank==2){
b=sqrt(3.24);
MPI_Send(&b,1,MPI_FLOAT,4,2,MPI_COMM_WORLD);
}
if(rank==3){
c=pow(8,2);
MPI_Send(&c,1,MPI_FLOAT,4,3,MPI_COMM_WORLD);
}
if(rank==4){
MPI_Recv(&a,1,MPI_FLOAT,1,1,MPI_COMM_WORLD,&status);
MPI_Recv(&b,1,MPI_FLOAT,2,2,MPI_COMM_WORLD,&status);
MPI_Recv(&c,1,MPI_FLOAT,3,3,MPI_COMM_WORLD,&status);
}
t2 = MPI_Wtime();
cout<<"Natija:"<MPI_Finalize();
return 0;
}



Download 2,33 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish