CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

problem using property udfs in parallel mode

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   June 24, 2009, 09:26
Default problem using property udfs in parallel mode
  #1
New Member
 
Ellen
Join Date: Mar 2009
Posts: 11
Rep Power: 8
EllenW is on a distinguished road
Hi,

I'm having a problem when trying to use multiple property udfs in the parallel mode:

I'm modeling two gases in species transport, and used two udf's to define their properties (thermal conductivity). The udf is quite simple: to open a file and read in a list of data, then specify the data to cells according to the cell temperature (see the attached code). Two such udfs were written, one for each gas, and they work well in the serial mode.
However, when I tried to use them in the parallel mode, problem occurred. I parallelized the code as attached. If I only apply one udf to one gas, it worked fine, but if I apply both udfs to both gases, then I got this error message:
Error: > (greater-than): invalid argument [2]: wrong type [not a number]
Error object: 1. #quan

Could anyone please help me explain why this happens? Or point out where I did wrong in parallelizing the code? Thank you very much!

The original udf:

#include "udf.h"
FILE *ifp;
int i;
real k_a[100][2];
DEFINE_EXECUTE_ON_LOADING(table_ka, libudfka)
{
real T, k;
ifp = fopen("k_a.txt", "r");
for (i=0;i<100;i++)
{
fscanf(ifp, "%lf %lf", &T, &k);
k_a[i][0] = T;
k_a[i][1] = k;
}
Message("k_a table was loaded.");
fclose(ifp);
}
DEFINE_PROPERTY(cell_ka, cell, thread)
{
real temp1, k1;
temp1 = C_T(cell, thread);
if(temp1<k_a[0][0])
k1 = k_a[0][1];
for (i=1;i<100;i++)
{
if(temp1>=k_a[i-1][0] && temp1<=k_a[i][0])
k1 = (k_a[i][1]-k_a[i-1][1])*(temp1-k_a[i-1][0])/(k_a[i][0]-k_a[i-1][0])+k_a[i-1][1];
}
if(temp1>k_a[99][0])
k1 = k_a[99][1];
return k1;
}

The parallelized udf:

#include "udf.h"
int i;
real C1[100];
real C2[100];
#if !RP_NODE
FILE *ifp1;
DEFINE_EXECUTE_ON_LOADING(table_ka, libudfka)
{
int ii;
real T1, k1;
ifp1 = fopen("k_a.txt", "r");
for (ii=0;ii<99;ii++)
{
fscanf(ifp1, "%lf %lf", &T1, &k1);
C1[ii] = T1;
C2[ii] = k1;
}
host_to_node_real(C1,100);
host_to_node_real(C2,100);
Message("k_a table was loaded.");
fclose (ifp1);
}
#endif
DEFINE_PROPERTY(cell_ka, cell, thread)
{
real temp1, k1;
real k_a[100][2];
for (i=0;i<100;i++)
{
k_a[i][0] = C1[i];
k_a[i][1] = C2[i];
}
#if !RP_HOST
temp1 = C_T(cell, thread);
if(temp1<k_a[0][0])
k1 = k_a[0][1];
for (i=1; i<100; i++)
{
if (temp1>=k_a[i-1][0] && temp1<=k_a[i][0])
k1 = (k_a[i][1]-k_a[i-1][1])*(temp1-k_a[i-1][0])/(k_a[i][0]-k_a[i-1][0])+k_a[i-1][1];
}
if(temp1>k_a[99][0])
k1 = k_a[99][1];
#endif
return k1;
}


Regards,
ellen
EllenW is offline   Reply With Quote

Old   June 25, 2009, 05:46
Default
  #2
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 8
coglione is on a distinguished road
Hi ellen,

this is just a wild guess, but could it be the problem that you defined i as global variable which then is used (and manipulated) by every processor simultaneously? Maybe the value of i within your "for-loops" gets messed up and causes the problem. Try to use local variables and see whether this works.

cheers
coglione is offline   Reply With Quote

Old   June 25, 2009, 10:21
Default
  #3
New Member
 
Ellen
Join Date: Mar 2009
Posts: 11
Rep Power: 8
EllenW is on a distinguished road
thanks for pointing this out, Coglione. I put "i" in local for the other udf, but forgot to do the same for this one. Now I corrected it, but the error is still there...

I also tried assigning some data to the property array inside the DEFINE_PROPERTY macro, instead of getting data by reading the property data file. I did this for both udfs, and they worked fine in the parallel mode. But when I changed back to file reading, then same problem: the case runs fine with only one udf, and error appears when both udfs are used...

thanks for any suggestions you may have.

ellen
EllenW is offline   Reply With Quote

Old   July 8, 2009, 16:28
Default
  #4
New Member
 
SK
Join Date: Jul 2009
Posts: 8
Rep Power: 8
friends.sk is on a distinguished road
Ellen,

You found an answer for this?? I am also stucked up at the same point.
friends.sk is offline   Reply With Quote

Old   July 9, 2009, 16:02
Default
  #5
New Member
 
Ellen
Join Date: Mar 2009
Posts: 11
Rep Power: 8
EllenW is on a distinguished road
Hi friends.sk, my code is working now. the two corrections I made to the DEFINE_EXECUTE_ON_LOADING part are:
Compiler directive should be within the execute loop.
Passing of variables from host to node should be outside the compiler directive loop

the second part (DEFINE_PROPERTY) was unchanged.

ellen
EllenW is offline   Reply With Quote

Old   July 10, 2009, 04:31
Default
  #6
New Member
 
SK
Join Date: Jul 2009
Posts: 8
Rep Power: 8
friends.sk is on a distinguished road
Hi Ellen, Thanks for the reply. Can you please explain me bit in detail.
Thanks.
SK.
friends.sk is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
RSH problem for parallel running in CFX Nicola CFX 5 June 18, 2012 18:31
DPM model in parallel batch mode Prashanth FLUENT 2 March 6, 2009 08:54
problem with parallel system tahere FLUENT 2 December 27, 2008 19:44
Problem using parallel Fluent Gustavo FLUENT 0 June 27, 2004 23:12
PROBLEM IN PARALLEL PROGRAMMING WITH MPI Niavarani Main CFD Forum 1 April 20, 2004 06:51


All times are GMT -4. The time now is 09:48.