Hi all,
I compiled my ispc code with -g flag and then used gdb to debug (my code is slower when parallelized then when serial, that is why I am debugging).
When going with gdb through my ispc code weird thing is happening: gdb does not execute code by order but it jumps from instruction to instruction. then advances few lines, than again jumpes from instruction to instruction (usualli between cifs) and so on.
So it does advance through code as it should, however every so it jumps unexplainably. Is it possible that code is actually executing that way? If so, why is that happening?
Here is my code:
foreach (diagI = 0 ... diag.size) {// for each field in diagonal -> calculate P, Q and D
//print("instanca % -> diagI %, %\n", programIndex, diagI);
int r = diagStart.r - diagI;
int c = diagStart.c + diagI;
Cost value;
//------ calc P -> it is calculated from left P and left D ------//
value = -1; // set cell value to undefined
cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
// Index in diag1 of field to the left -> uniform part.
// diag1I = diag1Start.r - r = diag1I_uni + diagI
uniform int diag1I_uni = diag1Start.r - diagStart.r;
// left D
Cost leftD = diag1.D[diag1I_uni+diagI];
value = leftD + cf.gapOpen;
// left P
Cost leftP = diag1.P[diag1I_uni+diagI];
cif (!(leftP < 0)) // if defined
value = min(value, leftP + cf.gapExt);
PRINT_MASK();
}
// store best value to cell
diag.P[diagI] = value;
//---------------------------------------------------------------//
//----- calc Q -> it is calculated from upper D and upper Q -----//
value = -1; // set cell value to undefined
cif (r-1 >= 0 && diag1Start.r >= r-1 && diag1End.r <= r-1) { // check if there is a field from diag1 above
// Index in diag1 of field above -> uniform part.
// diag1I = diag1Start.r - (r-1) = diag1I_uni + diagI
uniform int diag1I_uni = diag1Start.r - diagStart.r + 1;
// upper D
Cost upperD = diag1.D[diag1I_uni+diagI];
value = upperD + cf.gapOpen;
// upper Q
Cost upperQ = diag1.Q[diag1I_uni+diagI];
cif (!(upperQ < 0)) // if defined
value = min(value, upperQ + cf.gapExt);
PRINT_MASK();
}
// store best value to cell
diag.Q[diagI] = value;
//---------------------------------------------------------------//
//---- calc D -> it is calculated from P and Q from same field and from upper-left D ----//
value = max(cf.mismatch, cf.gapOpen) * (lengthA + lengthB) * 2; // set cell value to some big value (that will never be achieved)
// upper left D
cif (r-1 >= 0 && c-1 >= 0 && diag2Start.r >= r-1 && diag2End.r <= r-1) { // check if there is a field from diag2 to the upper-left
// Index in diag2 of field to upper left -> uniform part.
// diag2I = diag2Start.r - (r-1) = diag2I_uni + diagI
uniform int diag2I_uni = diag2Start.r - diagStart.r + 1;
char a_ = a[diagStart.r - 1 - diagI]; //a[r-1]
char b_ = b[diagStart.c - 1 + diagI]; //b[c-1]
Cost cost = (a_ == b_) ? 0 : cf.mismatch;
value = diag2.D[diag2I_uni+diagI] + cost;
}
// center P
cif (!(diag.P[diagI] < 0))
value = min(value, diag.P[diagI]);
// center Q
cif (!(diag.Q[diagI] < 0))
value = min(value, diag.Q[diagI]);
// store best value to cell
diag.D[diagI] = value;
//---------------------------------------------------------------------------------------//
}
And here is the output from gdb (
red parts are weird behaviour):
(gdb) step
49 foreach (diagI = 0 ... diag.size) {// for each field in diagonal -> calculate P, Q and D
(gdb) step
56 value = -1; // set cell value to undefined
(gdb) step
49 foreach (diagI = 0 ... diag.size) {// for each field in diagonal -> calculate P, Q and D
(gdb) step
113 diag.D[diagI] = value;
(gdb) step
57 cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
(gdb) step
56 value = -1; // set cell value to undefined
(gdb) step
51 int r = diagStart.r - diagI;
(gdb) step
52 int c = diagStart.c + diagI;
(gdb) step
56 value = -1; // set cell value to undefined
(gdb) step
57 cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
(gdb) step
67 value = min(value, leftP + cf.gapExt);
(gdb) step
60 uniform int diag1I_uni = diag1Start.r - diagStart.r;
(gdb) step
62 Cost leftD = diag1.D[diag1I_uni+diagI];
(gdb) step
57 cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
(gdb) step
62 Cost leftD = diag1.D[diag1I_uni+diagI];
(gdb) step
63 value = leftD + cf.gapOpen;
(gdb) step
65 Cost leftP = diag1.P[diag1I_uni+diagI];
(gdb) step
57 cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
(gdb) step
65 Cost leftP = diag1.P[diag1I_uni+diagI];
(gdb) step
57 cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
(gdb) step
66 cif (!(leftP < 0)) // if defined
(gdb) step
67 value = min(value, leftP + cf.gapExt);
(gdb) step
71 diag.P[diagI] = value;
(gdb) step
75 value = -1; // set cell value to undefined
(gdb) step
76 cif (r-1 >= 0 && diag1Start.r >= r-1 && diag1End.r <= r-1) { // check if there is a field from diag1 above
(gdb) step
57 cif (c-1 >= 0 && diag1Start.r >= r && diag1End.r <= r) { // check if there is a field from diag1 to the left
(gdb) step
76 cif (r-1 >= 0 && diag1Start.r >= r-1 && diag1End.r <= r-1) { // check if there is a field from diag1 above
(gdb) step
86 value = min(value, upperQ + cf.gapExt);As you can see at the end it jumps between cifs, and before it goes really weird, it does not follow the procedural flow, why does that happen?
Thank you in advance