Amaliyot Mijoz-server dasturiy ta'minot arxitekturasi Mijoz/server misollari 1


Download 21.21 Kb.
Sana19.06.2023
Hajmi21.21 Kb.
#1615468
Bog'liq
UZ ДТА Практ 10


Amaliyot 9. Mijoz-server dasturiy ta'minot arxitekturasi

Mijoz/server misollari
1 -misol Quyidagi misol mijoz/server interfeysidan foydalanishning eng oddiy usulini ko'rsatadi. U umuman xizmat nomlaridan foydalanmaydi.
Server tomondan:

char myportMPI_MAX_PORT_NAME ;

MPI_Comm interkom ;

/* ... */

MPI_Open_port (MPI_INFO_NULL, mening portim );

printf (``port nomi: %s n'', myport );

MPI_Comm_accept ( myport , MPI_INFO_NULL, 0, MPI_COMM_SELF,

& interkom );

/* interkom bilan biror narsa qiling */
Server terminalga port nomini chiqaradi va mijoz ishga tushganda foydalanuvchi uni kiritishi kerak (agar MPI ilovasi stdin-ni qo'llab-quvvatlasa , u ishlaydi).
Mijoz tomonidan:

MPI_Comm interkom ;

belgi nomiMPI_MAX_PORT_NAME ;

printf (``port nomini kiriting: '');

oladi (ism);

MPI_Comm_connect (nomi, MPI_INFO_NULL, 0, MPI_COMM_SELF,

& interkom );
2-misol. Ushbu misolda `` okean '' ilovasi okean-atmosfera bog'langan iqlim modelining `` orqa uchi'' qismidir. Bu MPI ilovasi nomlarni nashr etishini taxmin qiladi.
Server tomondan:

MPI_Open_port (MPI_INFO_NULL, port_name );

MPI_Publish_name (``okean'', MPI_INFO_NULL, port_name );

MPI_Comm_accept ( port_name , MPI_INFO_NULL, 0, MPI_COMM_SELF,

& interkom );

/* interkom bilan biror narsa qiling */

MPI_Unpublish_name (``okean'', MPI_INFO_NULL, port_name );
Shunday qilib tomonlar mijoz :

MPI_Lookup_name (``okean'', MPI_INFO_NULL, port_nomi );

MPI_Comm_connect ( port_name , MPI_INFO_NULL, 0, MPI_COMM_SELF,

& interkom );


3-misol Bu mijoz/server ilovasining oddiy misolidir. Server bir vaqtning o'zida faqat bitta ulanishni qabul qiladi va 1 tegli xabar olinmaguncha, ya'ni mijoz aloqani uzishni talab qilmaguncha bu ulanishga xizmat qiladi . Tegi 0 bo'lgan xabar serverni tugatishni aytadi. Server alohida jarayondir.

#include `` MPI.h ''

int main (int argc , char ** argv )

MPI_Comm mijozi;

MPI_Status holati;

char port_nameMPI_MAX_PORT_NAME ;

double bufMAX_DATA ;

int hajmi, yana;


MPI_Init (& argc , & argv );

MPI_Comm_size (MPI_COMM_WORLD, &hajmi);

agar (hajmi != 1) xato (FATAL, ``Server juda katta'');

MPI_Open_port (MPI_INFO_NULL, port_name );

printf (``server %s n manzilida mavjud '' , port_name );

while(1)

MPI_Comm_accept ( port_name , MPI_INFO_NULL, 0, MPI_COMM_WORLD,

&mijoz);

yana = 1;

esa (yana)

MPI_Recv ( buf , MAX.DATA, MPI_DOUBLE,

MPI_ANY_SOURCE, MPI_ANY_TAG, mijoz, &status );

almashtirish ( status.MPI_TAG )

holat 0: MPI_Comm_free ( &mijoz );

MPI_Close_port ( port_nomi );

MPI_Finalize ();

qaytish 0;

1-holat: MPI_Comm_disconnect (&mijoz);

yana = 0;

sindirish ;

-holat : /* biror narsa qiling */

...

standart :



/* noma’lum xabar turi */

MPI_Abort (MPI_COMM_WORLD, 1);










Mana mijoz kodi:

# `` MPI.h '' ni o'z ichiga oladi

int main (int argc , char ** argv )

MPI_Commserver ;

double bufMAX_DATA ;

char port_nameMPI_MAX_PORT_NAME ;


MPI_Init (& argc , & argv );

strcpy ( port_nomi , argv1); / * deylik _ Ism server */

/* - argument buyruq qatorlar */

MPI_Comm_connect ( port_name , MPI_INFO_NULL, 0, MPI_COMM_WORLD,

&server);

(!bajarilgan)

teg=2; /* Bajarish harakat */

MPI_Send ( buf , n, MPI_DOUBLE, 0, teg, server );

/* va hokazo. */



MPI_Send ( buf , 0, MPI_DOUBLE, 0, 1, server);

MPI_Comm_disconnect (&server);

MPI_Finalize ();



qaytish 0;


https://www.opennet.ru/docs/RUS/mpi-2/

-Server dastur arxitekturasidan foydalanishga misol keltiring
Download 21.21 Kb.

Do'stlaringiz bilan baham:




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