User Defined Function (UDFs) are functions that one can program and can be dynamically loaded along with the CFD Software Fluent Solver to enhance the standard features. UDFs are written in C programming Language.
Following is a section of my UDF:
/*Memory Allocation only at first call to the 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 the 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 with the above code compiling using VC++ in windows 32 bit. But in Windows 64 bit and Linux 32/64 bit (with GCC).. I get the following error:
==============================================================================
Stack backtrace generated for process id 10801 on signal 1 :
Please include this information with any bug report you file on this issue!
==============================================================================
Data.In is 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 a fatal signal (SEGMENTATION VIOLATION).
Can any of you help me over come this issue??
Your first allocation needs to allocate a pointer to a cell_t but you are allocating a cell_t. If cell_t
is 4 bytes in size then they is why it has worked so far on 32 bit (same size as a pointer) and fails on 64 bit. In the 64 bit case it would be smaller than a pointer, meaning you do not allocate enough memory and eventually overrun the bounds of what has been allocated. Your correct code should be:
Avg_CellAroundNode =(cell_t**)calloc((Nnum+1),sizeof(cell_t*));
That does not explain why it fails on 32 bit Linux though.