69 |
int NetCommunication::startPVM() |
int NetCommunication::startPVM() |
70 |
{ |
{ |
71 |
/* |
/* |
72 |
Þetta fall er afgreitt í bili! |
Þetta fall er afgreitt à bili! |
73 |
ATH: Þarf e.t.v. að skoða parametrana í MPI_Init. |
ATH: Þarf e.t.v. að skoða parametrana à MPI_Init. |
74 |
*/ |
*/ |
75 |
int info; |
int info; |
76 |
// Held að það sé í lagi að hafa bara NULL hér... |
// Held að það sé à lagi að hafa bara NULL hér... |
77 |
MPI_Init(NULL, NULL); |
MPI_Init(NULL, NULL); |
78 |
if (mytid < 0) |
if (mytid < 0) |
79 |
{ |
{ |
92 |
{ |
{ |
93 |
printErrorMsg("Error in netcommunication - MPI_Init has not been called!"); |
printErrorMsg("Error in netcommunication - MPI_Init has not been called!"); |
94 |
} |
} |
95 |
// nhost á að vera 1 hérna |
// nhost á að vera 1 hérna |
96 |
MPI_Comm_size(MPI_COMM_WORLD, &nhost); |
MPI_Comm_size(MPI_COMM_WORLD, &nhost); |
97 |
|
|
98 |
tids = new int[maxNumHosts]; |
tids = new int[maxNumHosts]; |
109 |
int NetCommunication::startNetCommunication() |
int NetCommunication::startNetCommunication() |
110 |
{ |
{ |
111 |
/* |
/* |
112 |
Þetta fall er afgreitt í bili! |
Þetta fall er afgreitt à bili! |
113 |
*/ |
*/ |
114 |
int i, OK, info; |
int i, OK, info; |
115 |
if (NETSTARTED == 1 && mytid >= 0) |
if (NETSTARTED == 1 && mytid >= 0) |
130 |
if (OK == 1) |
if (OK == 1) |
131 |
{ |
{ |
132 |
/* |
/* |
133 |
Í PVM var notað pvm_catchout(stdin) til að fá output úr |
� PVM var notað pvm_catchout(stdin) til að fá output úr |
134 |
child processunum, í MPI setur maður flag á eftir mpirun |
child processunum, à MPI setur maður flag á eftir mpirun |
135 |
til að fá sambærilega hegðun, þá búast til skrár fyrir hvert |
til að fá sambærilega hegðun, þá búast til skrár fyrir hvert |
136 |
process sem skrifa út allt sem kemur úr stdout og stderr í þeim. |
process sem skrifa út allt sem kemur úr stdout og stderr à þeim. |
137 |
*/ |
*/ |
138 |
MPI_Comm_spawn(slaveProgram, slaveArguments, nhost, MPI_INFO_NULL, |
MPI_Comm_spawn(slaveProgram, slaveArguments, nhost, MPI_INFO_NULL, |
139 |
0, MPI_COMM_WORLD, &intercomm, errcodes); |
0, MPI_COMM_WORLD, &intercomm, errcodes); |
158 |
} |
} |
159 |
|
|
160 |
/* |
/* |
161 |
Þýðandinn var eitthvað að kvarta hérna... |
Þýðandinn var eitthvað að kvarta hérna... |
162 |
for (i = 0; i < nhost; i++) |
for (i = 0; i < nhost; i++) |
163 |
{ |
{ |
164 |
|
|
206 |
void NetCommunication::stopNetCommunication() |
void NetCommunication::stopNetCommunication() |
207 |
{ |
{ |
208 |
/* |
/* |
209 |
Fínt í bili. |
FÃnt à bili. |
210 |
*/ |
*/ |
211 |
int i, tid, info, numTasks; |
int i, tid, info, numTasks; |
212 |
int stopparam = -1; |
int stopparam = -1; |
227 |
int NetCommunication::startProcesses() |
int NetCommunication::startProcesses() |
228 |
{ |
{ |
229 |
/* |
/* |
230 |
Þetta fall er afgreitt í bili! |
Þetta fall er afgreitt à bili! |
231 |
*/ |
*/ |
232 |
//Send number of variables, group name and number of processes to spawned processes |
//Send number of variables, group name and number of processes to spawned processes |
233 |
int cansend = 1; |
int cansend = 1; |
274 |
} |
} |
275 |
|
|
276 |
// check if process with identity = id is up and running |
// check if process with identity = id is up and running |
277 |
// spurning að sleppa þessu í bili, leyfum þessu að vera á meðan hitt er klárað. |
// spurning að sleppa þessu à bili, leyfum þessu að vera á meðan hitt er klárað. |
278 |
OK = checkProcess(id); |
OK = checkProcess(id); |
279 |
if (OK == 1) |
if (OK == 1) |
280 |
{ |
{ |
314 |
|
|
315 |
int NetCommunication::checkProcess(int id) { |
int NetCommunication::checkProcess(int id) { |
316 |
/* |
/* |
317 |
Þetta fall er ekki að gera neitt, því það sendir adrei nein |
Þetta fall er ekki að gera neitt, þvà það sendir adrei nein |
318 |
út með tagginu getTaskDiedTag() |
út með tagginu getTaskDiedTag() |
319 |
*/ |
*/ |
320 |
int info, bufID, recvTid, flag; |
int info, bufID, recvTid, flag; |
321 |
MPI_Status stats, recvstats; |
MPI_Status stats, recvstats; |
327 |
// Non-blocking probe which checks for a message with this tag, if there is no message then |
// Non-blocking probe which checks for a message with this tag, if there is no message then |
328 |
// flag is false, otherwise it is true, then something is maybe wrong with the process! |
// flag is false, otherwise it is true, then something is maybe wrong with the process! |
329 |
|
|
330 |
// ATH: Þetta flag mun líklega alltaf vera false... það tékkar bara strax og heldur svo |
// ATH: Þetta flag mun lÃklega alltaf vera false... það tékkar bara strax og heldur svo |
331 |
// áfram, þetta virkar eins og pvm_probe, svo þetta ætti að vera í lagi hér. |
// áfram, þetta virkar eins og pvm_probe, svo þetta ætti að vera à lagi hér. |
332 |
// Held samt að það sé irrelevant að vera með þetta checkprocess núna, það á allt að |
// Held samt að það sé irrelevant að vera með þetta checkprocess núna, það á allt að |
333 |
// vera í lagi... |
// vera à lagi... |
334 |
bufID = MPI_Iprobe(id, pvmConst->getTaskDiedTag(), intercomm, &flag, &stats); |
bufID = MPI_Iprobe(id, pvmConst->getTaskDiedTag(), intercomm, &flag, &stats); |
335 |
if (flag == true) { |
if (flag == true) { |
336 |
// message has arrived from tids[id] that has halted |
// message has arrived from tids[id] that has halted |
366 |
|
|
367 |
void NetCommunication::checkProcesses() { |
void NetCommunication::checkProcesses() { |
368 |
/* |
/* |
369 |
Þetta fall er komið í bili. |
Þetta fall er komið à bili. |
370 |
Þetta fall erl íka í raun óþarfi... |
Þetta fall erl Ãka à raun óþarfi... |
371 |
*/ |
*/ |
372 |
int i, info, tidDown, flag; |
int i, info, tidDown, flag; |
373 |
MPI_Request req; |
MPI_Request req; |
390 |
|
|
391 |
void NetCommunication::getHealthOfProcesses(int* procTids) { |
void NetCommunication::getHealthOfProcesses(int* procTids) { |
392 |
/* |
/* |
393 |
Þetta fall er afgreitt. |
Þetta fall er afgreitt. |
394 |
|
|
395 |
*/ |
*/ |
396 |
checkProcesses(); |
checkProcesses(); |
404 |
// ******************************************************** |
// ******************************************************** |
405 |
int NetCommunication::sendData(const ParameterVector& sendP) { |
int NetCommunication::sendData(const ParameterVector& sendP) { |
406 |
/* |
/* |
407 |
Komið í bili, þarf samt að skoða MPI_PACK eða eitthvað álíka til að |
Komið à bili, þarf samt að skoða MPI_PACK eða eitthvað álÃka til að |
408 |
raða inn í buffer og senda strengina, gæti verið að maður þurfi þá að |
raða inn à buffer og senda strengina, gæti verið að maður þurfi þá að |
409 |
pakka int með sem er lengd char fylkisins. Það er samt bara kallað á þetta |
pakka int með sem er lengd char fylkisins. Það er samt bara kallað á þetta |
410 |
fall einu sinni í byrjun til að senda switches, svo að það ætti að vera í lagi. |
fall einu sinni à byrjun til að senda switches, svo að það ætti að vera à lagi. |
411 |
!!! ATH !!! |
!!! ATH !!! |
412 |
Passa að allir sem kalla á þetta sendi communicator !!! |
Passa að allir sem kalla á þetta sendi communicator !!! |
413 |
!!! |
!!! |
414 |
*/ |
*/ |
415 |
// must absolutely check if this is possible or can not delete |
// must absolutely check if this is possible or can not delete |
425 |
// broadcasting the data via a tree structure, this should not create too much overhead. |
// broadcasting the data via a tree structure, this should not create too much overhead. |
426 |
for(int j = 0; j<nhost; j++) |
for(int j = 0; j<nhost; j++) |
427 |
{ |
{ |
428 |
MPI_Send(stringValue[i],strlen(stringValue[i]), MPI_BYTE, j, pvmConst->getMasterSendStringTag(), intercomm); |
MPI_Send(stringValue[i],strlen(stringValue[i])+1, MPI_BYTE, j, pvmConst->getMasterSendStringTag(), intercomm); |
429 |
} |
} |
430 |
}; |
}; |
431 |
assert(sendP.Size() >= numVar); |
assert(sendP.Size() >= numVar); |
448 |
|
|
449 |
int NetCommunication::sendData(const ParameterVector& sendP, int processID) { |
int NetCommunication::sendData(const ParameterVector& sendP, int processID) { |
450 |
/* |
/* |
451 |
Búið í bili... |
Búið à bili... |
452 |
*/ |
*/ |
453 |
int i, info; |
int i, info; |
454 |
char** stringValue; |
char** stringValue; |
462 |
// This could be causing some overhead, could consider packing it in a buffer |
// This could be causing some overhead, could consider packing it in a buffer |
463 |
// before I send it, like the old pvm version, let's see if this works ok. |
// before I send it, like the old pvm version, let's see if this works ok. |
464 |
// I think this function is only called once. |
// I think this function is only called once. |
465 |
MPI_Send(stringValue[i],strlen(stringValue[i]), MPI_BYTE,tids[processID],pvmConst->getMasterSendStringTag(),intercomm); |
MPI_Send(stringValue[i],strlen(stringValue[i])+1, MPI_BYTE,tids[processID],pvmConst->getMasterSendStringTag(),intercomm); |
466 |
}; |
}; |
467 |
assert(sendP.Size() >= numVar); |
assert(sendP.Size() >= numVar); |
468 |
|
|
481 |
int NetCommunication::sendBoundData(const DoubleVector& sendP) |
int NetCommunication::sendBoundData(const DoubleVector& sendP) |
482 |
{ |
{ |
483 |
/* |
/* |
484 |
Komið í bili... |
Komið à bili... |
485 |
*/ |
*/ |
486 |
int i, info; |
int i, info; |
487 |
double* temp; |
double* temp; |
509 |
int NetCommunication::sendBoundData(const DoubleVector& sendP, int processID) |
int NetCommunication::sendBoundData(const DoubleVector& sendP, int processID) |
510 |
{ |
{ |
511 |
/* |
/* |
512 |
Komið í bili! |
Komið à bili! |
513 |
*/ |
*/ |
514 |
int i, info; |
int i, info; |
515 |
double* temp; |
double* temp; |
534 |
int NetCommunication::sendData(NetDataVariables* sendP, int processID) |
int NetCommunication::sendData(NetDataVariables* sendP, int processID) |
535 |
{ |
{ |
536 |
/* |
/* |
537 |
Komið í bili! |
Komið à bili! |
538 |
*/ |
*/ |
539 |
int info; |
int info; |
540 |
int cansend = 1; |
int cansend = 1; |
583 |
int NetCommunication::receiveData(NetDataResult* rp) |
int NetCommunication::receiveData(NetDataResult* rp) |
584 |
{ |
{ |
585 |
/* |
/* |
586 |
Komið í bili... |
Komið à bili... |
587 |
Þarf að passa að kasta villu ef einhver af þessum nær ekki að receive-a, nota kannski |
Þarf að passa að kasta villu ef einhver af þessum nær ekki að receive-a, nota kannski |
588 |
MPI_Probe... |
MPI_Probe... |
589 |
*/ |
*/ |
590 |
int info; |
int info; |
596 |
MPI_Recv(&rp->result, 1, MPI_DOUBLE, status.MPI_SOURCE, pvmConst->getMasterReceiveDataTag(), intercomm, &status2); |
MPI_Recv(&rp->result, 1, MPI_DOUBLE, status.MPI_SOURCE, pvmConst->getMasterReceiveDataTag(), intercomm, &status2); |
597 |
MPI_Recv(&rp->who, 1, MPI_INT, status.MPI_SOURCE, pvmConst->getMasterReceiveDataTag(), intercomm, &status2); |
MPI_Recv(&rp->who, 1, MPI_INT, status.MPI_SOURCE, pvmConst->getMasterReceiveDataTag(), intercomm, &status2); |
598 |
MPI_Recv(&rp->x_id, 1, MPI_INT, status.MPI_SOURCE, pvmConst->getMasterReceiveDataTag(), intercomm, &status2); |
MPI_Recv(&rp->x_id, 1, MPI_INT, status.MPI_SOURCE, pvmConst->getMasterReceiveDataTag(), intercomm, &status2); |
599 |
cout << "Skrifa result úr netcomm: " << rp->result << "\n"; |
cout << "Skrifa result úr netcomm: " << rp->result << "\n"; |
600 |
return SUCCESS; |
return SUCCESS; |
601 |
} |
} |
602 |
else |
else |
647 |
void NetCommunication::printErrorMsg(const char* errorMsg) |
void NetCommunication::printErrorMsg(const char* errorMsg) |
648 |
{ |
{ |
649 |
/* |
/* |
650 |
Eina fallið sem ég virðist þurfa að eiga eitthvað við hér... |
Eina fallið sem ég virðist þurfa að eiga eitthvað við hér... |
651 |
*/ |
*/ |
652 |
char* msg; |
char* msg; |
653 |
msg = new char[strlen(errorMsg) + 1]; |
msg = new char[strlen(errorMsg) + 1]; |
654 |
strcpy(msg, errorMsg); |
strcpy(msg, errorMsg); |
655 |
// Ákvað að gera þetta svona, vona að þetta flood-i ekki command line... |
// �kvað að gera þetta svona, vona að þetta flood-i ekki command line... |
656 |
cout << msg << "\n"; |
cout << msg << "\n"; |
657 |
delete[] msg; |
delete[] msg; |
658 |
cerr << errorMsg << endl; |
cerr << errorMsg << endl; |
693 |
int MasterCommunication::receiveData(NetDataResult* rp) |
int MasterCommunication::receiveData(NetDataResult* rp) |
694 |
{ |
{ |
695 |
/* |
/* |
696 |
Komið í bili... |
Komið à bili... |
697 |
Þarf að passa að kasta villu ef einhver af þessum nær ekki að receive-a, nota kannski |
Þarf að passa að kasta villu ef einhver af þessum nær ekki að receive-a, nota kannski |
698 |
MPI_Probe, þetta var gert með Timeout receive í gömlu útgáfunni... |
MPI_Probe, þetta var gert með Timeout receive à gömlu útgáfunni... |
699 |
*/ |
*/ |
700 |
int info; |
int info; |
701 |
MPI_Status status, status2; |
MPI_Status status, status2; |