void prijmiPraci() { //??? push 0 pred push message[1]? //message[0]=Mindex //message[1]=koren //message[2..2+Mindex]=M; int message[DELKA]; MPI_Recv(message, DELKA, MPI_INT, MPI_ANY_SOURCE, posilam_praci, MPI_COMM_WORLD, &status); data->Mindex = message[0]; zasobnik.push(ODDELOVAC); zasobnik.push(message[1]); for (int i = 0; i <= data->Mindex; i++) { data->M[i] = message[i + 2]; } #ifdef DEBUG1 if (my_rank == 1) { cout << "P1: Mindex=" << data->Mindex << " ZASOBNIK PO PRIJATE PRACI: "; zasobnik.vypis(); vypisPole(data->M, data->Mindex); } #endif #ifdef DEBUG cout << "P" << my_rank << ": PRIJAL PRACI OD PROCESORU P" << status.MPI_SOURCE << endl; cout << "ZASOBNIK PO PRIJATE PRACI: "; zasobnik.vypis(); cout << "Mindex=" << data->Mindex << endl; #endif }
void odesliReseni() { int message[DELKA]; for (int i = 0; i < data->m; i++) { message[i] = data->M_BEST[i]; } if (my_rank != 0) { MPI_Send(message, DELKA, MPI_INT, 0, reseni, MPI_COMM_WORLD); } #ifdef DEBUG cout << "P" << my_rank << ": POSILAM SVOJE NEJLEPSI RESENI PROCESORU P0" << endl; cout << "RESENI: "; vypisPole(data->M_BEST, data->m); #endif }
void posliPraci(int dst) { //message[0]=Mindex //message[1]=koren //message[2..2+Mindex]=M; int message[DELKA]; //message[0] = data->Mindex; message[0] = 0; message[1] = zasobnik.pop_dno(); //odebrali a poslali jsme cislo ze dna zasobniku, jedem dal for (int i = 2; i < 2 + data->Mindex; i++) { message[i] = data->M[i - 2]; } MPI_Send(message, DELKA, MPI_INT, dst, posilam_praci, MPI_COMM_WORLD); #ifdef DEBUG cout << "P" << my_rank << ": POSILAM PRACI PROCESORU " << dst << endl; cout << "POSILANA DATA: "; vypisPole(message, 10); #endif }
void initPole(int *pole, int *delka) { char bubu[100]; printf("Aktualni obsah pole:\n"); vypisPole(pole,*delka); printf("Zadat jine hodnoty? (A/N)\n"); char *bubucpy=fgets(bubu, 100, stdin); if(bubucpy==NULL) { printf("Neocekavany konec souboru\n"); exit(0); } char c=0; if(strlen(bubu)!=0) { c=bubu[0]; } char digit[100]; char *tempch; int ok=1; int i; if((c=='A')||(c=='a')) { printf("Zadavejte hodnoty oddelene novym radkem, konec=K:\n"); *delka=0; int digitint; char k=0; do { tempch=fgets(digit, 100, stdin); if(tempch!=NULL) { if (digit[strlen(digit)-1]=='\n') { digit[strlen(digit)-1]='\0'; } }else{ printf("Neocekavany konec souboru\n"); exit(0); } if(strlen(digit)!=0) { k=digit[0]; } if((k=='k')||(k=='K')) { break; } if(strlen(digit)==0) { ok=0; printf("Nespravny format, zkuste znovu\n"); }else{ ok=1; } for (i=0;i<strlen(digit);++i) { if (!isdigit(digit[i])) { ok=0; printf("Nespravny format, zkuste znovu\n"); break; } } if(ok==1) { digitint=atoi(digit); pole[*delka]=digitint; (*delka)=(*delka) +1; } }while(1); } }