Skip to content

Commit

Permalink
add linCmt memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattfidler committed Oct 6, 2023
1 parent 74b5214 commit 2a9e7eb
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/rxData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,10 @@ struct rx_globals {

// time per thread
double *timeThread = NULL;
double *linCmtLag = NULL;
double *linCmtF = NULL;
double *linCmtDur = NULL;
double *linCmtRate = NULL;
};


Expand Down Expand Up @@ -1413,7 +1417,6 @@ extern "C" void setIndPointersByThread(rx_solving_options_ind *ind) {
ind->cDur = getDurThread();
ind->cF = getFThread();
ind->InfusionRate = getInfusionRateThread();
//ind->linCmtRate = ind->InfusionRate + op->neq;
ind->tlastS = getTlastSThread();
ind->tfirstS = getTfirstSThread();
ind->curDoseS = getCurDoseSThread();
Expand Down Expand Up @@ -1442,6 +1445,10 @@ extern "C" void setIndPointersByThread(rx_solving_options_ind *ind) {
ind->solveSave = _globals.gSolveSave + (op->neq+ op->extraCmt)*omp_get_thread_num();
ind->solveLast = _globals.gSolveLast + (op->neq + op->extraCmt) *omp_get_thread_num();
ind->solveLast2 = _globals.gSolveLast2 + (op->neq+ op->extraCmt)*omp_get_thread_num();
ind->linCmtLag = _globals.linCmtLag + omp_get_thread_num()*2;
ind->linCmtF = _globals.linCmtF + omp_get_thread_num()*2;
ind->linCmtDur = _globals.linCmtDur + omp_get_thread_num()*2; // [n9]
ind->linCmtRate = _globals.linCmtRate + omp_get_thread_num()*2; // [n9]
} else {
ind->alag = NULL;
ind->cRate =NULL;
Expand All @@ -1455,6 +1462,7 @@ extern "C" void setIndPointersByThread(rx_solving_options_ind *ind) {
ind->solveSave = NULL;
ind->solveLast = NULL;
ind->solveLast2 = NULL;
ind->linCmtLag = NULL;
}
ind->timeThread = _globals.timeThread + rx->maxAllTimes*omp_get_thread_num();
ind->llikSave = _globals.gLlikSave + op->nLlik*rxLlikSaveSize*omp_get_thread_num();
Expand Down Expand Up @@ -2485,7 +2493,7 @@ LogicalVector rxSolveFree(){
_globals.gomega = NULL;
if (_globals.gsigma != NULL) free(_globals.gsigma);
_globals.gsigma = NULL;

_globals.zeroTheta = false;
_globals.zeroOmega = false;
_globals.zeroSigma = false;
Expand Down Expand Up @@ -5295,8 +5303,9 @@ SEXP rxSolve_(const RObject &obj, const List &rxControl,
int nIndSim = rx->nIndSim;
int n7 = nIndSim * rx->nsub * rx->nsim;
int n8 = rx->maxAllTimes*op->cores;
int n9 = 2*op->cores;
if (_globals.gsolve != NULL) free(_globals.gsolve);
_globals.gsolve = (double*)calloc(n0+nLin+3*nsave+n2+ n4+n5_c+n6+ n7 + n8 +
_globals.gsolve = (double*)calloc(n0+nLin+3*nsave+n2+ n4+n5_c+n6+ n7 + n8 + 4*n9 +
5*op->neq + 8*n3a_c + nllik_c,
sizeof(double));// [n0]
#ifdef rxSolveT
Expand Down Expand Up @@ -5332,11 +5341,15 @@ SEXP rxSolve_(const RObject &obj, const List &rxControl,
_globals.gssAtol=_globals.gssRtol + op->neq; //[op->neq]
// All NA_REAL fill are below; one statement to initialize them all
rx->ypNA = _globals.gssAtol + op->neq; // [op->neq]
_globals.gTlastS = rx->ypNA + op->neq; // [n3a_c]
_globals.gTfirstS = _globals.gTlastS + n3a_c; // [n3a]
_globals.gCurDoseS = _globals.gTfirstS + n3a_c; // [n3a]
_globals.gIndSim = _globals.gCurDoseS + n3a_c;// [n7]
_globals.timeThread = _globals.gIndSim + n7;
_globals.gTlastS = rx->ypNA + op->neq; // [n3a_c]
_globals.gTfirstS = _globals.gTlastS + n3a_c; // [n3a]
_globals.gCurDoseS = _globals.gTfirstS + n3a_c; // [n3a]
_globals.gIndSim = _globals.gCurDoseS + n3a_c;// [n7]
_globals.linCmtLag = _globals.gIndSim + n7; // [n9]
_globals.linCmtF = _globals.linCmtLag + n9; // [n9]
_globals.linCmtDur = _globals.linCmtF + n9; // [n9]
_globals.linCmtRate = _globals.linCmtDur + n9; // [n9]
_globals.timeThread = _globals.linCmtRate + n9;
std::fill_n(rx->ypNA, op->neq, NA_REAL);

std::fill_n(&_globals.gatol2[0],op->neq, atolNV[0]);
Expand Down

0 comments on commit 2a9e7eb

Please sign in to comment.