Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions inst/include/rxode2parseGetTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ static inline double getLag(rx_solving_options_ind *ind, int id, int cmt, double
}
double ret = LAG(id, cmt, time);
if (ISNA(ret)) {
op->badSolve=1;
if (op->naTime == 0) {
op->naTime = 1 + 10*cmt;
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
int curNaTime;
#pragma omp atomic read
curNaTime = op->naTime;
if (curNaTime == 0) {
int newNaTime = 1 + 10*cmt;
#pragma omp atomic write
op->naTime = newNaTime;
}
}
return ret;
Expand All @@ -51,9 +58,16 @@ static inline double getRate(rx_solving_options_ind *ind, int id, int cmt, doubl
returnBadTime(t);
double ret = RATE(id, cmt, dose, t);
if (ISNA(ret)){
op->badSolve=1;
if (op->naTime == 0) {
op->naTime = 2 + 10*cmt;
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
int curNaTime;
#pragma omp atomic read
curNaTime = op->naTime;
if (curNaTime == 0) {
int newNaTime = 2 + 10*cmt;
#pragma omp atomic write
op->naTime = newNaTime;
}
}
return ret;
Expand All @@ -65,9 +79,16 @@ static inline double getDur(rx_solving_options_ind *ind, int id, int cmt, double
if (ISNA(t)) return t;
double ret = DUR(id, cmt, dose, t);
if (ISNA(ret)){
op->badSolve=1;
if (op->naTime == 0) {
op->naTime = 3 + 10*cmt;
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
int curNaTime;
#pragma omp atomic read
curNaTime = op->naTime;
if (curNaTime == 0) {
int newNaTime = 3 + 10*cmt;
#pragma omp atomic write
op->naTime = newNaTime;
}
}
return ret;
Expand Down Expand Up @@ -340,9 +361,16 @@ static inline double handleInfusionItem(int idx, rx_solve *rx, rx_solving_option
ind->idx = oIdx;
if (ISNA(f)){
rx_solving_options *op = &op_global;
op->badSolve=1;
if (op->naTime == 0) {
op->naTime = 4 + 10*ind->cmt;
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
int curNaTime;
#pragma omp atomic read
curNaTime = op->naTime;
if (curNaTime == 0) {
int newNaTime = 4 + 10*ind->cmt;
#pragma omp atomic write
op->naTime = newNaTime;
}
}
double durOld = (getAllTimes(ind, ind->idose[infEidx]) -
Expand Down
77 changes: 42 additions & 35 deletions inst/include/rxode2parseHandleEvid.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,17 @@ static inline double getAmt(rx_solving_options_ind *ind, int id, int cmt,
double ret = AMT(id, cmt, dose, t, y);
if (ISNA(ret)){
rx_solving_options *op = &op_global;
op->badSolve=1;
op->naTime = 5 + 10*cmt;
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
int curNaTime;
#pragma omp atomic read
curNaTime = op->naTime;
if (curNaTime == 0) {
int newNaTime = 5 + 10*cmt;
#pragma omp atomic write
op->naTime = newNaTime;
}
}
return ret;
}
Expand All @@ -309,20 +318,22 @@ static inline int pushIgnoredDose(int doseIdx, rx_solving_options_ind *ind) {
}
if (ind->ignoredDosesN[0]+1 >= ind->ignoredDosesAllocN[0]) {
rx_solving_options *op = &op_global;
int allocFailed = 0;
#pragma omp critical
{
int *tmpI = (int*)realloc(ind->ignoredDoses, (ind->ignoredDosesN[0]+1+EVID_EXTRA_SIZE)*sizeof(int));
if (tmpI == NULL) {
op->badSolve = 1;
// return 0;
allocFailed = 1;
} else {
ind->ignoredDoses = tmpI;
ind->ignoredDosesAllocN[0] = (ind->ignoredDosesN[0]+1+EVID_EXTRA_SIZE);
re = 1;
}
}
if (op->badSolve) {
return 0; // don't continue if we have a bad solve.
if (allocFailed) {
#pragma omp atomic write
op->badSolve = 1;
return 0;
}
}
ind->ignoredDoses[ind->ignoredDosesN[0]] = doseIdx;
Expand All @@ -334,19 +345,21 @@ static inline int pushPendingDose(int doseIdx, rx_solving_options_ind *ind) {
int re = 0;
if (ind->pendingDosesN[0]+1 >= ind->pendingDosesAllocN[0]) {
rx_solving_options *op = &op_global;
int allocFailed = 0;
#pragma omp critical
{
int *tmpI = (int*)realloc(ind->pendingDoses, (ind->pendingDosesN[0]+1+EVID_EXTRA_SIZE)*sizeof(int));
if (tmpI == NULL) {
op->badSolve = 1;
//return 0;
allocFailed = 1;
} else {
ind->pendingDoses = tmpI;
ind->pendingDosesAllocN[0] = (ind->pendingDosesN[0]+1+EVID_EXTRA_SIZE);
re = 1;
}
}
if (op->badSolve == 1) {
if (allocFailed) {
#pragma omp atomic write
op->badSolve = 1;
return 0;
}
}
Expand All @@ -361,32 +374,29 @@ static inline int pushDosingEvent(double time, double amt, int evid,
int re = 0;
if (ind->extraDoseN[0]+1 >= ind->extraDoseAllocN[0]) {
rx_solving_options *op = &op_global;
int allocFailed = 0; // 0=ok, 1=partial alloc, -1=first alloc failed
#pragma omp critical
{
int *tmpI = (int*)realloc(ind->extraDoseTimeIdx, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(int));
if (tmpI == NULL) {
op->badSolve = -1;
// return 0;
allocFailed = -1;
} else {
ind->extraDoseTimeIdx = tmpI;

tmpI = (int*)realloc(ind->extraDoseEvid, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(int));
if (tmpI == NULL) {
op->badSolve = 1;
// return 1;
allocFailed = 1;
} else {
ind->extraDoseEvid = tmpI;
double * tmpD = (double*)realloc(ind->extraDoseTime, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(double));
if (tmpD == NULL) {
op->badSolve = 1;
//return 1;
allocFailed = 1;
} else {
ind->extraDoseTime = tmpD;

tmpD = (double*)realloc(ind->extraDoseDose, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(double));
if (tmpD == NULL) {
op->badSolve = 1;
//return 1;
allocFailed = 1;
} else {
ind->extraDoseDose = tmpD;

Expand All @@ -397,11 +407,11 @@ static inline int pushDosingEvent(double time, double amt, int evid,
}
}
}
if (op->badSolve == 1) {
return 1;
} else if (op->badSolve == -1) {
op->badSolve = 1; // set to bad solve.
return 0;
if (allocFailed != 0) {
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
return (allocFailed == 1) ? 1 : 0;
}
}
ind->extraDoseTimeIdx[ind->extraDoseN[0]] = ind->extraDoseN[0];
Expand All @@ -419,33 +429,30 @@ static inline int pushUniqueDosingEvent(double time, double amt, int evid,
int re = 0;
if (ind->extraDoseN[0]+1 >= ind->extraDoseAllocN[0]) {
rx_solving_options *op = &op_global;
int allocFailed = 0; // 0=ok, 1=partial alloc, -1=first alloc failed
#pragma omp critical
{
int *tmpI = (int*)realloc(ind->extraDoseTimeIdx, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(int));
if (tmpI == NULL) {
op->badSolve = -1;
// return 0;
allocFailed = -1;
} else {
ind->extraDoseTimeIdx = tmpI;

tmpI = (int*)realloc(ind->extraDoseEvid, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(int));
if (tmpI == NULL) {
op->badSolve = 1;
// return 1;
allocFailed = 1;
} else {
ind->extraDoseEvid = tmpI;

double * tmpD = (double*)realloc(ind->extraDoseTime, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(double));
if (tmpD == NULL) {
op->badSolve = 1;
//return 1;
allocFailed = 1;
} else {
ind->extraDoseTime = tmpD;

tmpD = (double*)realloc(ind->extraDoseDose, (ind->extraDoseN[0]+1+EVID_EXTRA_SIZE)*sizeof(double));
if (tmpD == NULL) {
op->badSolve = 1;
// return 1;
allocFailed = 1;
} else {
ind->extraDoseDose = tmpD;

Expand All @@ -455,11 +462,11 @@ static inline int pushUniqueDosingEvent(double time, double amt, int evid,
}
}
}
if (op->badSolve == 1) {
return 1; // don't continue if we have a bad solve.
} else if (op->badSolve == -1) {
op->badSolve = 1; // set to bad solve.
return 0;
if (allocFailed != 0) {
int newBadSolve = 1;
#pragma omp atomic write
op->badSolve = newBadSolve;
return (allocFailed == 1) ? 1 : 0;
}
re = 1;
}
Expand Down
Loading
Loading