user defined functions - Segment violation issue with UDF (C code) writtern for CFD solver Fluent -


user defined function (udfs) functions 1 can program , can dynamically loaded along cfd software fluent solver enhance standard features. udfs written in c programming language.

following section of udf:

/*memory allocation @ first call subroutine*/ if(cellaroundnodefirstcallflag==0) {     cellaroundnodefirstcallflag=1;     avg_cellaroundnode =(cell_t**)calloc((nnum+1),sizeof(cell_t));     for(i=0;i<nnum;i++)     {         avg_cellaroundnode[i] =(cell_t*)calloc((ncellanode+1),sizeof(cell_t));     } }  if (avg_cellaroundnode!=null)         {             message("check: not null.... \n");                       }   message("check enter... \n.");  message("check:array size %d %d \n",nnum,ncellanode);  /*initializing matrix*/ for(i=0;i<nnum;i++) {     for(j=0;j<ncellanode;j++)     {         message("check:initalizing cell: %d %d \n",i,j);         avg_cellaroundnode[i][j]=-1;     } }  message("check  exit...."); 

i have no issues above code compiling using vc++ in windows 32 bit. in windows 64 bit , linux 32/64 bit (with gcc).. following error:

   ==============================================================================    stack backtrace generated process id 10801 on signal 1 :    please include information bug report file on issue!    ==============================================================================     data.in read...    check: not null....     check enter...     check:array size 10 20     check:initalizing cell: 0 0     check:initalizing cell: 0 1     check:initalizing cell: 0 2     .    .    check:initalizing cell: 7 18     check:initalizing cell: 7 19     check:initalizing cell: 8 0     /opt/fluent.inc/fluent6.3.26/lnamd64/2ddp/fluent.6.3.26[0xcc0e0b]    /opt/fluent.inc/fluent6.3.26/lnamd64/2ddp/fluent.6.3.26[0xcc0d61]    /lib64/libpthread.so.0[0x355aa0de70]    bubudf/lnamd64/2ddp/libudf.so(nodeavg+0x104)[0x2ba2089bc1bd]    error: fluent.6.3.26 received fatal signal (segmentation violation). 

can of me on come issue??

your first allocation needs allocate pointer cell_t allocating cell_t. if cell_t 4 bytes in size why has worked far on 32 bit (same size pointer) , fails on 64 bit. in 64 bit case smaller pointer, meaning not allocate enough memory , overrun bounds of has been allocated. correct code should be:

avg_cellaroundnode =(cell_t**)calloc((nnum+1),sizeof(cell_t*)); 

that not explain why fails on 32 bit linux though.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -