PDA

View Full Version : Error code 200



stanca
09-03-2007, 06:07 AM
Hi, I am using the IMSL library for the C++ version of Microsoft Visual Studio 8. My code works for a low iteration number and it breaks when I am increasing the iteration with the following message

Error in reading imslerr.bin.
Out-of-space.

*** TERMINAL error from imsl_f_random_uniform. Error code 200.

Does anyone know what causes this?

Thanks,
Stanca
Duke University

brian
09-03-2007, 08:39 AM
Hello Stanca,

IMSL error codes are associated with error messages in <vni_dir>\imsl\cnl600\ms32pc\bin\imslerr.dat (where <vni_dir> is C:\Program Files\VNI by default). These are compiled into the resource file imslerr.bin (same location).

From this file: 200 IMSL_OUT_OF_MEMORY Not enough memory.

There are two points to consider here.

1) In order for IMSL to access these files, IMSLERRPATH and IMSLSERRPATH must be set in your environment. This is typically done during the install where a dialog appears asking if you would like the IMSL install to configure your environment.

If you don't want to reinstall, I recommend manually modifying three environment variables before starting Visual C++ 8:


a) IMSLERRPATH - <vni_dir>\cnl600\ms32pc\bin
b) IMSLSERRPATH - <vni_dir>\cnl600\ms32pc\bin
c) Path - (append) <vni_dir>\imsl\cnl600\ms32pc\lib

Item c is necessary so that the system can locate dlls that might be used and loaded at runtime.

2) For any degree of certainty in addressing the memory issue, I would need to see your code. Taking a guess, I would say you are likely dealing with a memory leak. You might be able to see this behavior in the Windows Task Manager:

a) ctrl+alt+delete
b) select Task Manager
c) select the performance tab (cpu and memory usage is displayed in real time).
You may want to generate the total number of random numbers you need in the first call (performance alternative - one array) or confirm that in each iteration the old array is being freed in your loop. Managing arrays is critical. If you have a leak here you may want to check elsewhere in you code for similar occurrences.

FYI: 64 bit operating systems permit varying sizes of application space (much more that 32 bit) but the default for Windows 32 is limited to 2 GB for applications and 2 GB for the OS. This can be modified marginally (memory leaks can consume the difference) as indicated here: 4-Gigabyte Tuning (http://msdn2.microsoft.com/en-us/library/bb613473.aspx).

Regards,

brian

stanca
09-03-2007, 12:23 PM
Hi Brian. How do I manually modify

a) IMSLERRPATH - <vni_dir>\cnl600\ms32pc\bin
b) IMSLSERRPATH - <vni_dir>\cnl600\ms32pc\bin
c) Path - (append) <vni_dir>\imsl\cnl600\ms32pc\lib

Also, you were right about the memory usage. The CPU is arround 50 and the virtual memory goes over the top. Here is how my code looks

void optim(double parBest[]){
double *var;
double *fvec;
double xguess[4]={ 3, 0.5, -3.5, 2.7};
double xlb[4]={2, 0.1, -6, 1};
double J, xub[4]={7, 5, 0, 5};
int ibtype = 0;
void fcn(int, int, double [], double []);
int nTOT=22, nobs=17;
int nPar=4;
double xscale[4]={1, 0.1, 1, 1};
double step_tol=1e-8;
int ndigit=3;

var = imsl_d_bounded_least_squares(fcn, nTOT, nPar, ibtype, xlb, xub, IMSL_XGUESS, xguess, IMSL_STEP_TOL, step_tol,
IMSL_GOOD_DIGIT, ndigit,IMSL_FVEC, &fvec, 0);

parBest[0]=var[0];
parBest[1]=var[1];
parBest[2]=var[2];
parBest[3]=var[3];

imsl_d_write_matrix("The result is", 1, 4, var, 0);
imsl_d_write_matrix("The residuals are", 1, nTOT, fvec, 0);
J=pow(fvec[0],2)+pow(fvec[1],2)+pow(fvec[2],2)+pow(fvec[3],2)+pow(fvec[4],2)+pow(fvec[5],2)+pow(fvec[6],2)+pow(fvec[7],2)+
pow(fvec[8],2)+pow(fvec[9],2)+pow(fvec[10],2)+pow(fvec[11],2)+pow(fvec[12],2)+pow(fvec[13],2)+
pow(fvec[14],2)+pow(fvec[15],2)+pow(fvec[16],2)+pow(fvec[17],2)+pow(fvec[18],2)+pow(fvec[19],2)+ pow(fvec[20],2)+pow(fvec[21],2);
printf("J=%f\n",J);

FILE *fout_param = fopen("optim.txt","w");
fprintf(fout_param,"parBest[0]=%f\n", var[0]);
fprintf(fout_param,"parBest[1]=%f\n", var[1]);
fprintf(fout_param,"parBest[2]=%f\n", var[2]);
fprintf(fout_param,"parBest[3]=%f\n", var[3]);
fclose(fout_param);
getch();
}

void fcn(int nTOT, int nPar, double var[], double f[])
{
double t;
double Ttot[nobs], DKL[nobs];
:mad::mad:
int nRep=15;
:mad::mad::mad:
double xBase=55;
int s,i,j,k;
double tobs[17];
double tiny=1e-9;

i=j=k=0;
while(i<nData && j<nDKL)
{
if(DaysT[i]<=DaysDKL[j])
if (DaysT[i]<DaysDKL[j])
{
tobs[k] = DaysT[i];
k=k+1;
i=i+1;
}
else
{
tobs[k]=DaysT[i];
k=k;
i=i+1;
}
else
{
tobs[k] =DaysDKL[j];
k=k+1;
j=j+1;

}
}
if(i<nData)
for(j=i; j<nData; j++)
{
tobs[k++] = DaysT[j];
}
else
for(i=j; i<nDKL; i++)
{
tobs[k++] = DaysDKL[i];
}


for(i=0; i<nobs; i++){
Ttot [i]=0; DKL[i]=0;
}
for (int iRep = 0; iRep < nRep; iRep++){
t=0;
initializeTCells();
for (int i=0; i<nobs;i++){
Ttot[i] += log(xBase+alpha*evolveTCells(t,tobs[i],pow(10,var[0]), var[1], pow(10,var[2]), 1, pow(10,var[3]), hill));
DKL[i] += log(getStats()+tiny);
t = tobs[i];
}
}
for(i=0; i<nobs; i++){
Ttot[i]=Ttot[i]/nRep; DKL[i]=DKL[i]/nRep;
}

t=0; s=0; i=0; j=0;
for(s=0; s<nobs; s++){
if(tobs[s]==DaysT[i] && tobs[s]!=DaysDKL[j])
{
f[i]=log(DIG026T[i][1]) - Ttot[s];
i=i+1;
}

if(tobs[s]!=DaysT[i] && tobs[s]==DaysDKL[j])
{
f[nData+j]=log(DIG026DKL[j]) - DKL[s];
j=j+1;
}

if (tobs[s]==DaysT[i] && tobs[s]==DaysDKL[j])
{
f[i]=log(DIG026T[i][1]) - Ttot[s];
f[nData+j]=log(DIG026DKL[j]) - DKL[s];
i=i+1; j=j+1;

}

}

}

When int nRep<15 it works fine, when is bigger than 15 it breaks. How do I fix a memory lekeage?


Thanks,
Stanca

brian
09-03-2007, 05:35 PM
Hello Stanca,

1) Modifying environment variables (assuming Windows XP):

When you create these, you can elect to create User or System variables. If you wish to make the libraries available to other users, you should choose System Variables.

Select Start
Right click "My Computer"
Select "properties"
Select the Advanced tab.
Click the "Environment Variables" button.
For each variable identified, select the new button to display the editing dialog.
Select OK.
After creating the variables select OK in the Environment Variable dialog.
Click OK in the System Properties dialog.


2) Reviewing the code... There is one IMSL function here (bounded least squares). This requires a function pointer argument. The function uses local variables and function calls.


a) The local variables will be on the stack (not dynamically allocated - malloc()). So these will not be related to the memory issue.
b) There are 3 function for which I have no code and all are called within the controlling loop 0 -> nRep. You should examine the functions initializeTCells(), evolveTCells() and getStats() for any malloc()s or IMSL calls where you have not freed memory. You may want to use the undocumented IMSL free routines:

void imsl_free_allocated_memory(void *p)
void imsls_free_allocated_memory(void *p)

These will preclude any issue associated with switching between Release and Debug versions of the Microsoft runtime libraries (free() (http://forums.vni.com/showthread.php?t=237&highlight=free#2)).

Regards,

brian

stanca
09-04-2007, 05:17 AM
Brian, I have tried to free the memory as you suggested and my program still crushes. Here's all of it. Am I not inserting the comands properly or maybe there is another issue. Thanks for helping!!!

Stanca

// digeorge_optim1.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include<conio.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <imsl.h>
using namespace std;

const int nFam = 18;
const int nCDR3 = 14;
const long nData=16;
const long nDKL=6;
const long nTOT=22;
const long nobs=17;
double tobs[nobs];
double pairsT[nobs][4], pairsDKL[nobs][4];
const int MnSpec=1000000;
int nPar=3;
double qFam[nFam], qFamCum[nFam];
double par[3], parBest[3];
double xTot, j;
double qCDR3[14][18], qCDR3Cum[14][18];
double DIG026T[nData][2], DIG026DKL[nDKL];
int *DaysT, *DaysDKL, *CDR3Length, fam[MnSpec], CDR3[MnSpec];
double xEq=1e+9, sigma, beta, rho, alpha=8e-7, len, hill=2.2;
double xzero=1;
double tFinal = 1000;
int nSpec;
double x[MnSpec];
double dt = 0.1;
double q2, q3, q4;
double DKL_flow;
double DKL_CDR3[nFam];
double DKL_tot;
FILE *fout;

char* fout_param = new char(100);

void readDIG026TData(){
char* fname="DIG026_T.txt";

// open the file for reading
FILE* f = fopen(fname,"r");

// initialize data
char* temp = new char[1024];
DaysT = new int[nData];

// read header line (dummy read)
fgets(temp, 1024,f);
// for each line in the table
for (int i = 0; i < nData; i++) {

// read first character in the line
fscanf(f, "%d", &DaysT[i]);

// read the values in the line
for (int j = 0; j < 2; j++) {
fscanf(f, "%lf", &DIG026T[i][j]);
}
}


// close the file
fclose(f);
}


void readDIG026DKLData(){
char* fname="DIG026_DKL.txt";

// open the file for reading
FILE* f = ::fopen(fname,"r");

// initialize data
char* temp = new char[1024];
DaysDKL = new int[nDKL];

// read header line (dummy read)
::fgets(temp, 1024, f);
// for each line in the table
for (int i = 0; i < nDKL; i++) {

// read first character in the line
::fscanf(f, "%d", &DaysDKL[i]);

// read the values in the line
::fscanf(f, "%lf", &DIG026DKL[i]);

}


// close the file
::fclose(f);
}

void readFlowData() {
char* fname = "control_CD4_flow.txt";
//int iunit;
//int freeFileUnit;
//int ioStatus;
//char dummy[10];

// qFamCum = new double(nFam);
// qFam = new double(nFam);
char* temp = new char[100];

FILE *f = fopen(fname,"r");

for (int i = 0; i < nFam; i++) {
fscanf(f, "%s", temp);
fscanf(f, "%lf", &qFam[i]);
// printf("%d: %lf\n",i, qFam[i]);
}

qFamCum[0] = qFam[0];
for (int i = 1; i < nFam; i++) {
qFamCum[i] = qFam[i] + qFamCum[i-1];
}

fclose(f);
}

void readSpectratypeData() {
char* fname = "control_CD4_spectratype.txt";

// open the file for reading
FILE* f = ::fopen(fname,"r");

// initialize data
char* temp = new char[1024];
CDR3Length = new int[nCDR3];

// read header line (dummy read)
::fgets(temp, 1024,f);

// for each line in the table
for (int i = 0; i < nCDR3; i++) {

// read first character in the line
::fscanf(f, "%d", &CDR3Length[i]);

// read the values in the line
for (int j = 0; j < nFam; j++) {
::fscanf(f, "%lf", &qCDR3[i][j]);
}
}

// close the file
::fclose(f);

for (int i = 0; i < nFam; i++) {
qCDR3Cum[0][i] = qCDR3[0][i];
for (int j = 1; j < nCDR3; j++) {
qCDR3Cum[j][i] = qCDR3[j][i] + qCDR3Cum[j-1][i];
}
}
}


int getFam(){
int iFam;
double u;
u = *imsl_f_random_uniform (1, 0);


for (iFam = 1; iFam < nFam; iFam++) {
if (u <= qFamCum[iFam]){
return iFam;
}
}
void imsl_free_allocated_memory(void *u);
return iFam;

}

int iCDR3(int iFam) {

double u;

u = *imsl_f_random_uniform (1, 0);


for (int i = 1; i < nCDR3; i++) {
if (u < qCDR3Cum[i][iFam]) {
return i;
}
}
void imsl_free_allocated_memory(void *u);
return nCDR3;


}

void initializeTCells(){

double lambda, gamma;
/*printf("Before:%lf\n", sigma);
changeDouble("Change sigma", &sigma);*/
// Define lambda
// Define gamma


lambda = rho * beta * MnSpec / xEq;
gamma = beta * (1 - rho)/ xEq;

nSpec = 1;


for (int i = 0; i < MnSpec; i++) {
x[i] = 0;
}


fam[0] = getFam();
CDR3[0] = iCDR3(fam[1]);


}


double sumX(int nSpec) {
double result = 0.0;
for (int i=0; i < nSpec; i++) {
result += x[i];
}
return result;
}

double evolveTCells(double t, double tEnd, double sigma, double beta, double rho, double xzero, double len, double hill) {
double intensity;
int deltaN;
int iSpec;
xTot=xzero;

double lambda, gamma;
lambda = rho * beta * MnSpec / xEq;
gamma = beta * (1 - rho)/ xEq;


double u;

while (t < tEnd) {

xTot=xzero+sumX(nSpec);

for (iSpec = 0; iSpec < nSpec; iSpec++) {
x[iSpec] = x[iSpec] + dt *(beta - gamma * xTot - lambda * x[iSpec]) * x[iSpec];

}

// intensity = sigma * dt;
t = t + dt;

intensity = sigma *dt*pow(t,hill)/(pow(len,hill)+pow(t, hill));

if (sigma > 0){

deltaN = *imsl_random_poisson (1, intensity, 0);
for (int i = 0; i < deltaN; i++) {
u = *imsl_d_random_uniform (1, 0);

if (u * MnSpec > nSpec-1) {
if (nSpec < MnSpec-1) {
nSpec = nSpec + 1;
x[nSpec] = 1;
fam[nSpec] = getFam();
CDR3[nSpec] = iCDR3(fam[nSpec]);
}
else {

u = *imsl_f_random_uniform (1, 0);
//u = rand();
//u = u / RAND_MAX;

iSpec = u * nSpec + 1;
x[iSpec] = x[iSpec]+1;
}
}
}
}
}
void imsl_free_allocated_memory(void *u);
void imsl_free_allocated_memory(void *deltaN);
return xTot;
}
double getStats() {

double pFam[nFam];
double pCDR3[nCDR3][nFam];
double tot[nFam];


xTot=xzero;
for (int iSpec = 0; iSpec < nSpec; iSpec++){
xTot = xTot + x[iSpec];
}

q2 = xzero*xzero;
for (int iSpec = 0; iSpec < nSpec; iSpec++) {
q2 = q2 + x[iSpec] * x[iSpec];
}
//printf("q2=\%E\n",q2);

if (xTot > 0) q2 = q2 / (xTot * xTot);

q3 = xzero*xzero*xzero;
for (int iSpec = 0; iSpec < nSpec; iSpec++) {
q3 = q3 + x[iSpec] * x[iSpec] * x[iSpec];
}
//printf("q3=\%E\n",q3);

if (xTot > 0) q3 = q3 / (xTot * xTot * xTot);

q4 = xzero*xzero*xzero*xzero;
for (int iSpec = 0; iSpec < nSpec; iSpec++) {
q4 = q4 + x[iSpec] * x[iSpec] * x[iSpec] * x[iSpec];
}
if (xTot > 0) q4 = q4 / (xTot * xTot * xTot * xTot);

for (int i = 0; i < nFam; i++) {
pFam[i] = 0;
}
// printf("nSpec: %d", nSpec);
for (int iSpec = 0; iSpec < nSpec; iSpec++) {
if(x[iSpec]>0){
pFam[fam[iSpec]] = pFam[fam[iSpec]] + x[iSpec];
}
}

for (int i = 0; i < nFam; i++) {
pFam[i] = pFam[i]/sumX(nSpec);
}



DKL_flow = 0;

for (int i = 0; i < nFam; i++) {
if (pFam[i] > 0){
DKL_flow = DKL_flow + pFam[i] * log(pFam[i] / qFam[i]);
}
}
for (int i = 0; i< nFam; i++) {
tot[i] = 0;
for (int j = 0; j < nCDR3; j++) {
pCDR3[j][i] = 0;
}
}
for (int iSpec = 0; iSpec < nSpec; iSpec++) {
pCDR3[CDR3[iSpec]][fam[iSpec]] = pCDR3[CDR3[iSpec]][fam[iSpec]] + x[iSpec];
tot[fam[iSpec]] = tot[fam[iSpec]] + x[iSpec];
}

for (int i = 0; i < nFam; i++) {
for (int j = 0; j < nCDR3; j++) {
if (tot[i] != 0) {
pCDR3[j][i] = pCDR3[j][i] / tot[i];
}
}
}


for (int i = 0; i< nFam; i++) {
DKL_CDR3[i] = 0;
}

for (int i = 0; i<nFam; i++) {
if (tot[i] == 0) {
DKL_CDR3[i] = 1e-10; // DKL_CDR3(i) = 0.0/0.0
}
else {
for (int j = 0; j < nCDR3; j++) {
if (pCDR3[j][i] >0) {
DKL_CDR3[i] = DKL_CDR3[i] + pCDR3[j][i] * log (pCDR3[j][i] / qCDR3[j][i]);
}
}
}
}

DKL_tot = DKL_flow;

for (int i = 0; i< nFam; i++) {
if (pFam[i] > 0) {
DKL_tot = DKL_tot + pFam[i] * DKL_CDR3[i];
}
}
// printf("-----------: 1\n");
fflush(stdout);
return DKL_tot;
}

void openFile(char *fname) {
fout = fopen(fname,"w");
}


void writeData(double t) {
fprintf(fout, "%lf\t%d\t%e\t%lf\t%lf\t%lf\t%lf", t, nSpec, 55+alpha*xTot, q2, q3, q4, DKL_flow);
for (int i = 0; i < nFam; i++) {
// fprintf(fout,"\t%.2E", DKL_CDR3[i]);
}
//fprintf(fout,"\t%lf\t", j);

fprintf(fout,"\t%lf\n", DKL_tot);
}

void optim(double parBest[]){
double *var;
double *fvec;
double xguess[4]={ 3, 0.5, -3.5, 2.7};
double xlb[4]={2, 0.1, -6, 1};
double J, xub[4]={7, 5, 0, 5};
int ibtype = 0;
void fcn(int, int, double [], double []);
int nTOT=22, nobs=17;
int nPar=4;
double xscale[4]={1, 0.1, 1, 1};
double step_tol=1e-8;
int ndigit=3;

var = imsl_d_bounded_least_squares(fcn, nTOT, nPar, ibtype, xlb, xub, IMSL_XGUESS, xguess, IMSL_STEP_TOL, step_tol,
IMSL_GOOD_DIGIT, ndigit,IMSL_FVEC, &fvec, 0);

parBest[0]=var[0];
parBest[1]=var[1];
parBest[2]=var[2];
parBest[3]=var[3];

imsl_d_write_matrix("The result is", 1, 4, var, 0);
imsl_d_write_matrix("The residuals are", 1, nTOT, fvec, 0);
J=pow(fvec[0],2)+pow(fvec[1],2)+pow(fvec[2],2)+pow(fvec[3],2)+pow(fvec[4],2)+pow(fvec[5],2)+pow(fvec[6],2)+pow(fvec[7],2)+
pow(fvec[8],2)+pow(fvec[9],2)+pow(fvec[10],2)+pow(fvec[11],2)+pow(fvec[12],2)+pow(fvec[13],2)+
pow(fvec[14],2)+pow(fvec[15],2)+pow(fvec[16],2)+pow(fvec[17],2)+pow(fvec[18],2)+pow(fvec[19],2)+ pow(fvec[20],2)+pow(fvec[21],2);
printf("J=%f\n",J);

FILE *fout_param = fopen("optim.txt","w");
fprintf(fout_param,"parBest[0]=%f\n", var[0]);
fprintf(fout_param,"parBest[1]=%f\n", var[1]);
fprintf(fout_param,"parBest[2]=%f\n", var[2]);
fprintf(fout_param,"parBest[3]=%f\n", var[3]);
fclose(fout_param);
getch();
void imsl_free_allocated_memory(void *var);
void imsl_free_allocated_memory(void *fvec);
}

void fcn(int nTOT, int nPar, double var[], double f[])
{
double t;
double Ttot[nobs], DKL[nobs];
int nRep=15;
double xBase=55;
int s,i,j,k;
double tobs[17];
double tiny=1e-9;

i=j=k=0;
while(i<nData && j<nDKL)
{
if(DaysT[i]<=DaysDKL[j])
if (DaysT[i]<DaysDKL[j])
{
tobs[k] = DaysT[i];
k=k+1;
i=i+1;
}
else
{
tobs[k]=DaysT[i];
k=k;
i=i+1;
}
else
{
tobs[k] =DaysDKL[j];
k=k+1;
j=j+1;

}
}
if(i<nData)
for(j=i; j<nData; j++)
{
tobs[k++] = DaysT[j];
}
else
for(i=j; i<nDKL; i++)
{
tobs[k++] = DaysDKL[i];
}


for(i=0; i<nobs; i++){
Ttot [i]=0; DKL[i]=0;
}
for (int iRep = 0; iRep < nRep; iRep++){
t=0;
initializeTCells();
for (int i=0; i<nobs;i++){
Ttot[i] += log(xBase+alpha*evolveTCells(t,tobs[i],pow(10,var[0]), var[1], pow(10,var[2]), 1, pow(10,var[3]), hill));
DKL[i] += log(getStats()+tiny);
t = tobs[i];
}
}
for(i=0; i<nobs; i++){
Ttot[i]=Ttot[i]/nRep; DKL[i]=DKL[i]/nRep;
}

t=0; s=0; i=0; j=0;
for(s=0; s<nobs; s++){
if(tobs[s]==DaysT[i] && tobs[s]!=DaysDKL[j])
{
f[i]=log(DIG026T[i][1]) - Ttot[s];
i=i+1;
}

if(tobs[s]!=DaysT[i] && tobs[s]==DaysDKL[j])
{
f[nData+j]=log(DIG026DKL[j]) - DKL[s];
j=j+1;
}

if (tobs[s]==DaysT[i] && tobs[s]==DaysDKL[j])
{
f[i]=log(DIG026T[i][1]) - Ttot[s];
f[nData+j]=log(DIG026DKL[j]) - DKL[s];
i=i+1; j=j+1;

}

}

}



int _tmain(int argc, _TCHAR* argv[])
{
double t;
double tSample = 1.0;
double tEnd=0;
t=0;
time_t timeSeed;
time(&timeSeed);
long seed=timeSeed;
srand(timeSeed);
char* fname = "DiGeorgeSim1.txt";

initializeTCells();
readDIG026TData();
readDIG026DKLData();
readFlowData();
readSpectratypeData();
optim(parBest);
initializeTCells();
openFile(fname);
//evolveTCells(t, tEnd, sigma, beta, rho, l, h);

/*while (t <= tFinal)
{
tEnd = t + tSample;

evolveTCells(t, tEnd, sigma, beta, rho);

t = tEnd;
}*/




t=0;
sigma=pow(10,parBest[0]);
beta=parBest[1];
rho=pow(10, parBest[2]);
len=pow(10, parBest[3]);
xzero=1;

printf("sigma=%lf", sigma);
printf("beta=%lf", beta);
printf("rho=%lf", rho);
getch();
while (t <= tFinal)
{

tEnd = t + tSample;

evolveTCells(t, tEnd, sigma, beta, rho, xzero, len, hill);
getStats();

fflush(stdout);
writeData(t);

t = tEnd;

}

fclose(fout);
return 0;
}

brian
09-04-2007, 01:29 PM
Hello Stanca,

After playing with some configuration settings I managed to compile this. I still could not run it without the specified data file (assertion error). You may want to contact VNI support with a zipped Visual Studio solution and some data that approximates what you are using. I've added some code below which may satisfy your concerns about the random number generator.

I did a quick review of the code and noticed some memory you could be more explicit in managing:

All pointers should be scrutinized. In particular:

I can't find a use for the global variable char* fout_param (not to be confused with the File * fout_param;
char* fout_param = new char(100);
Global variables which are never deallocated until the program concludes.
int *DaysT, *DaysDKL, *CDR3Lengt?
local variables such as char* temp in void readDIG026TData(), readDIG026DKLData(), void readFlowData(), void readSpectratypeData() should be deleted (delete [] temp; ).


Code tests:

In the first test my implementation is similar to yours (return one value at a time). You can see that 10000 iterations did not create a memory error.
void test1(int n)
{
double r;
imsls_random_seed_set(123457);

for (int i=0; i<n; i++){
r = *imsls_d_random_triangular(1, 0);
std::cout << "r = " << r << " iteration: " << i <<std::endl;
}
}
In the second test I set up my recommended implementation where an array of random numbers is generated and pulled for use later. Again there is no memory issue with 10000 random numbers.
void test2(int n)
{
for (int i=0; i<n; i++){
std::cout << "x = " << x[i] << " iteration: " << i <<std::endl;
}
}


Here's the full code:


#include <imsls.h>
#include <iostream>

void test1(int n);
void test2(int n);

double* x;

void main()
{
int n = 10000;
imsls_random_seed_set(123457);
x=imsls_d_random_triangular(n, 0);
test1(n);
test2(n);
void imsls_free_allocated_memory(void *x);
}

void test1(int n)
{
double r;
imsls_random_seed_set(123457);

for (int i=0; i<n; i++){
r = *imsls_d_random_triangular(1, 0);
std::cout << "r = " << r << " iteration: " << i <<std::endl;
}
}

void test2(int n)
{
for (int i=0; i<n; i++){
std::cout << "x = " << x[i] << " iteration: " << i <<std::endl;
}
}

Regards,

brian

stanca
09-06-2007, 02:14 PM
Brian, I have tried your test code and it runs just fine. I also tried to manage all my pointers properly but it didn't stop my code from using close to 70% CPU and crashing.

I am not sure what else to do but contact IMSL support. Thanks for your help.

Stanca