next up previous contents
Next: ðÒÉÍÅÒ 4 Up: ðÒÉÍÅÒÙ Previous: ðÒÉÍÅÒ 2   Contents

ðÒÉÍÅÒ 3

main(int argc, char **argv) { int me, count, count2; void *send_buf, *recv_buf, *send_buf2, *recv_buf2; MPI_Group MPI_GROUP_WORLD, grprem; MPI_Comm commslave; static int ranks[] = {0}; ... MPI_Init(&argc, &argv); MPI_Comm_group(MPI_COMM_WORLD, &MPI_GROUP_WORLD); MPI_Comm_rank(MPI_COMM_WORLD, &me); /* ÌÏËÁÌØÎÏ */ MPI_Group_excl(MPI_GROUP_WORLD, 1, ranks, &grprem);/* ÌÏËÁÌØÎÏ */ MPI_Comm_create(MPI_COMM_WORLD, grprem, &commslave); if(me != 0) { /* ×ÙÞÉÓÌÅÎÉÑ ÎÁ ÐÏÄÞÉÎÅÎÎÏÍ ÐÒÏÃÅÓÓÅ */ ... MPI_Reduce(send_buf,recv_buff,count, MPI_INT, MPI_SUM, 1, commslave); ... } /* ÐÒÏÃÅÓÓ ÎÕÌØ ÏÓÔÁÎÁ×ÌÉ×ÁÅÔÓÑ ÎÅÍÅÄÌÅÎÎÏ ÐÏÓÌÅ ×ÙÐÏÌÎÅÎÉÑ ÜÔÏÇÏ reduce, ÄÒÕÇÉÅ ÐÒÏÃÅÓÓÙ - ÐÏÚÖÅ... */ MPI_Reduce(send_buf2, recv_buff2, count2, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); MPI_Comm_free(&commslave); MPI_Group_free(&MPI_GROUP_WORLD); MPI_Group_free(&grprem); MPI_Finalize(); }

üÔÏÔ ÐÒÉÍÅÒ ÉÌÌÀÓÔÒÉÒÕÅÔ, ËÁË ÉÚ ÉÓÈÏÄÎÏÊ ÇÒÕÐÐÙ ÓÏÚÄÁÅÔÓÑ ÇÒÕÐÐÁ, ÓÏÄÅÒÖÁÝÁÑ ×ÓÅ ÐÒÏÃÅÓÓÙ, ËÒÏÍÅ ÐÒÏÃÅÓÓÁ ÎÕÌØ, É ÚÁÔÅÍ, ËÁË ÆÏÒÍÉÒÕÅÔÓÑ ËÏÍÍÕÎÉËÁÔÏÒ (commslave) ÄÌÑ ÜÔÏÊ ÎÏ×ÏÊ ÇÒÕÐÐÙ. îÏ×ÙÊ ËÏÍÍÕÎÉËÁÔÏÒ ÉÓÐÏÌØÚÕÅÔÓÑ × ËÏÌÌÅËÔÉ×ÎÏÍ ÏÂÒÁÝÅÎÉÉ É ×ÓÅ ÐÒÏÃÅÓÓÙ ×ÙÐÏÌÎÑÀÔÓÑ × ËÏÎÔÅËÓÔÅ MPI_COMM_WORLD. ðÒÉÍÅÒ ÉÌÌÀÓÔÒÉÒÕÅÔ, ËÁË ÜÔÉ Ä×Á ËÏÍÍÕÎÉËÁÔÏÒÁ (ËÏÔÏÒÙÅ ÏÂÑÚÁÔÅÌØÎÏ ÏÂÌÁÄÁÀÔ ÒÁÚÌÉÞÎÙÍÉ ËÏÎÔÅËÓÔÁÍÉ) ÚÁÝÉÝÁÀÔ ÏÂÍÅÎ. üÔÏ ÏÚÎÁÞÁÅÔ, ÞÔÏ ÏÂÍÅÎ × MPI_COMM_WORLD ÉÚÏÌÉÒÏ×ÁÎ ÏÔ ÏÂÍÅÎÁ × commslave É ÎÁÏÂÏÒÏÔ.

÷ ÏÂÝÅÍ, ``ÂÅÚÏÐÁÓÎÏÓÔØ ÇÒÕÐÐÙ'' ÄÏÓÔÉÇÁÅÔÓÑ ÞÅÒÅÚ ËÏÍÍÕÎÉËÁÔÏÒÙ, ÐÏÔÏÍÕ ÞÔÏ ÒÁÚÌÉÞÎÙÅ ËÏÎÔÅËÓÔÙ × ÐÒÅÄÅÌÁÈ ËÏÍÍÕÎÉËÁÔÏÒÏ× Ñ×ÌÑÀÔÓÑ ÕÎÉËÁÌØÎÙÍÉ ÎÁ ÌÀÂÏÍ ÐÒÏÃÅÓÓÅ.



Alex Otwagin 2002-12-10