Matrices in baseline C++ (no vector) implementation of PairHMM are now

allocated on heap using "new". Stack allocation led to program crashes
for large matrix sizes.
This commit is contained in:
Karthik Gururaj 2014-02-07 23:22:05 -08:00
parent 20a46e4098
commit a03d83579b
1 changed files with 100 additions and 79 deletions

View File

@ -1,7 +1,7 @@
#include "headers.h" #include "headers.h"
#include "template.h" #include "template.h"
#include "utils.h" #include "utils.h"
using namespace std;
template<class NUMBER> template<class NUMBER>
NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log) NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log)
{ {
@ -11,10 +11,29 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log)
Context<NUMBER> ctx; Context<NUMBER> ctx;
NUMBER M[ROWS][COLS]; //allocate on heap in way that simulates a 2D array. Having a 2D array instead of
NUMBER X[ROWS][COLS]; //a straightforward array of pointers ensures that all data lies 'close' in memory, increasing
NUMBER Y[ROWS][COLS]; //the chance of being stored together in the cache. Also, prefetchers can learn memory access
NUMBER p[ROWS][6]; //patterns for 2D arrays, not possible for array of pointers
NUMBER* common_buffer = new NUMBER[3*ROWS*COLS + ROWS*6];
//pointers to within the allocated buffer
NUMBER** common_pointer_buffer = new NUMBER*[4*ROWS];
NUMBER* ptr = common_buffer;
unsigned i = 0;
for(i=0;i<3*ROWS;++i, ptr+=COLS)
common_pointer_buffer[i] = ptr;
for(;i<4*ROWS;++i, ptr+=6)
common_pointer_buffer[i] = ptr;
//NUMBER M[ROWS][COLS];
//NUMBER X[ROWS][COLS];
//NUMBER Y[ROWS][COLS];
//NUMBER p[ROWS][6];
NUMBER** M = common_pointer_buffer;
NUMBER** X = M + ROWS;
NUMBER** Y = X + ROWS;
NUMBER** p = Y + ROWS;
p[0][MM] = ctx._(0.0); p[0][MM] = ctx._(0.0);
p[0][GapM] = ctx._(0.0); p[0][GapM] = ctx._(0.0);
@ -22,6 +41,7 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log)
p[0][XX] = ctx._(0.0); p[0][XX] = ctx._(0.0);
p[0][MY] = ctx._(0.0); p[0][MY] = ctx._(0.0);
p[0][YY] = ctx._(0.0); p[0][YY] = ctx._(0.0);
for (r = 1; r < ROWS; r++) for (r = 1; r < ROWS; r++)
{ {
int _i = tc->i[r-1] & 127; int _i = tc->i[r-1] & 127;
@ -36,7 +56,6 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log)
//p[r][MY] = (r == ROWS - 1) ? ctx._(1.0) : ctx.ph2pr[_d]; //p[r][MY] = (r == ROWS - 1) ? ctx._(1.0) : ctx.ph2pr[_d];
//p[r][YY] = (r == ROWS - 1) ? ctx._(1.0) : ctx.ph2pr[_c]; //p[r][YY] = (r == ROWS - 1) ? ctx._(1.0) : ctx.ph2pr[_c];
} }
for (c = 0; c < COLS; c++) for (c = 0; c < COLS; c++)
{ {
M[0][c] = ctx._(0.0); M[0][c] = ctx._(0.0);
@ -84,7 +103,6 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log)
//CONVERT_AND_PRINT(Y[r][c]); //CONVERT_AND_PRINT(Y[r][c]);
} }
for (c = 0; c < COLS; c++) for (c = 0; c < COLS; c++)
{ {
result += M[ROWS-1][c] + X[ROWS-1][c]; result += M[ROWS-1][c] + X[ROWS-1][c];
@ -93,6 +111,9 @@ NUMBER compute_full_prob(testcase *tc, NUMBER *before_last_log)
if (before_last_log != NULL) if (before_last_log != NULL)
*before_last_log = result; *before_last_log = result;
delete common_pointer_buffer;
delete common_buffer;
return result; return result;
//return ctx.LOG10(result) - ctx.LOG10_INITIAL_CONSTANT; //return ctx.LOG10(result) - ctx.LOG10_INITIAL_CONSTANT;
} }