Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include "pvm3.h"
- void parent(char* programName);
- void child();
- int main(int argc, char* argv[]) {
- if(pvm_parent() == PvmNoParent) parent(argv[0]);
- else child();
- return 0;
- }
- void parent(char* programName) {
- const int SIZE = 200;
- int vectorX[SIZE], vectorY[SIZE];
- int ZD[SIZE], ZU[SIZE];
- //W tym miejscu vectorX oraz vectorY powinny zostać zainicjalizowane
- int tidmaster;
- int ilhost, ilarch, tid;
- struct pvmhostinfo *info;
- tidmaster = pvm_mytid();
- pvm_config(&ilhost, &ilarch, &info);
- int index = 0;
- for(; index < ilhost; index++) {
- pvm_spawn(programName, 0, PvmTaskHost, info[index].hi_name, 1, &tid);
- pvm_initsend(PvmDataDefault);
- pvm_pkint(&vectorX[index]);
- pvm_pkint(&vectorY[index]);
- pvm_pkint(&index);
- pvm_send(&tid, 100);
- }
- int result, appendIndex;
- while(index < SIZE) {
- pvm_recv(-1, 200);
- pvm_upkint(&result, 1, 1);
- pvm_upkint(&appendIndex, 1, 1);
- pvm_upkint(&tid, 1, 1);
- if(result > 0) {
- ZD[appendIndex] = result;
- ZU[appendIndex] = 999;
- } else if (result < 0) {
- ZD[appendIndex] = 999;
- ZU[appendIndex] = result;
- } else {
- ZD[appendIndex] = 999;
- ZU[appendIndex] = 999;
- }
- pvm_initsend(PvmDataDefault);
- pvm_pkint(&vectorX[index]);
- pvm_pkint(&vectorY[index]);
- pvm_pkint(&index);
- pvm_send(&tid, 100);
- index++;
- }
- int i = 0;
- for(; i < ilhost; i++) {
- pvm_recv(-1, 200);
- pvm_upkint(&result, 1, 1);
- pvm_upkint(&appendIndex, 1, 1);
- pvm_upkint(&tid, 1, 1);
- if(result > 0) {
- ZD[appendIndex] = result;
- ZU[appendIndex] = 999;
- } else if (result < 0) {
- ZD[appendIndex] = 999;
- ZU[appendIndex] = result;
- } else {
- ZD[appendIndex] = 999;
- ZU[appendIndex] = 999;
- }
- pvm_kill(tid);
- }
- pvm_exit();
- exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement