I was trying to reproduce the error. But I ended up with another problem. Now I get segmentation fault in the function servant, towards the end. When I use the electric fence with gdb I get the following error message:
Program received signal SIGSEGV, Segmentation fault.
0x08055c51 in servant(float*, int, int, float*, char*, char*, int) (chrom=0x6265445f,
nchrom=3106677, chrom_len=4, fit=0x4015afd4,
workdir=0xbfffdd10 "/home/chellapp/Combi_chem/Non_mpi_eugene_Debug/",
outputdir=0xbfffdcc0 "/home/chellapp/Combi_chem/Non_mpi_eugene_Debug/", arguments=6)
at servant.cpp:41
41 fit[i+1]=i+1;
We can see that the second argument nchrom has a huge number. When I print nchrom, just before function call as well as in the function, it prints 10. I am not sure what's wrong with this servant function call. Any help is highly appreciated.
This is the piece of my main function
#include <iostream>
using namespace std;
int main(const int argc, const char *argv[])
{
char inputfile[80],outputfile[80],zscorefile[80];
char workdir[80],outputdir[80];
if(argc<6)
{
cerr<<"Use: .exe combi.inp echrom.txt zscore workdir outputdir"
<<endl;
exit(1);
}
strcpy(inputfile,argv[1]);
strcpy(outputfile,argv[2]);
strcpy(zscorefile,argv[3]);
strcpy(workdir,argv[4]);
strcpy(outputdir,argv[5]);
ofstream outfile(outputfile,ios:

ut);
if(!outfile)
{
cerr<<outputfile<<" File could not be opened"<<endl;
exit(1);
}
ofstream ofile(zscorefile,ios:

ut);
if(!ofile)
{
cerr<<zscorefile<<" File could not be opened"<<endl;
exit(1);
}
//Get the user definitions here
user myself;
myself.get_user_info(inputfile);
//Get the template
tmpl Templ;
Templ.getData(myself.Tmplfile,myself.ntmpl);
//Get the size of fragment libraries
int *nfgs=NULL;
int totalfgs;
nfgs=new int[myself.ntmpl_sub];
totalfgs=get_fgs(nfgs,myself.ntmpl_sub,myself.libarr,
myself.libsubarr,myself.subarr);
chromosome *chrs =NULL;
float *chrom=NULL;
chrs=new chromosome[myself.nchrom+1];
chrom=new float [myself.nchrom*myself.ntmpl_sub+1];
cout<<"chrom is allowed to have "<<myself.nchrom*myself.ntmpl_sub+1<<" values "<<endl;
master(chrs,chrom,myself.nchrom,nfgs,myself.ntmpl_sub);
float *fit_nrg=NULL;
fit_nrg= new float[myself.nchrom+1];
cout<<"fit_nrg is allowed to have "<<myself.nchrom+1<<" values "<<endl;
servant(chrom,myself.nchrom,myself.ntmpl_sub,fit_nrg,workdir,outputdir,argc);
cout<<"Complete: "<<endl;
delete []chrom;
delete []chrs;
delete []nfgs;
return 0;
}
This is my servant function:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include "Combi_main.h"
using namespace std;
int servant(float chrom[], int nchrom, int chrom_len,
float fit[], char workdir[], char outputdir[],int arguments)
{
int i,j,nc;
int dummy;
char str1[80];
for(i=0;i<nchrom;i++)
{
fit[i+1]=i+1;
cout<<" Chromosome fitness in servant "<<i+1<<" : "<<fit[i+1]<<endl;
}
return 0;
}