CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

UDF Parallelization

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 22, 2020, 08:30
Default UDF Parallelization
  #1
New Member
 
Join Date: May 2020
Posts: 23
Rep Power: 5
Bibill is on a distinguished road
Dear all,

I have written a UDF in which i read a text file and store the data in a float vector to perform some computations on it. Typically, some descriptive statistics computations.

I have tested the code in a C compiler and it works well. However when i use it as a UDF in Fluent, the results differ, probably due to the parallel computation since it only does mathematics and does not access any data or information from Fluent in my UDF.

For instance, different nodes give me different values for a same variable.

Can anyone explain me how to force Fluent to treat the code like i would be treated by a simple C compiler (e.g Xcode) ?

Thanks in advance!
Bibill is offline   Reply With Quote

Old   June 22, 2020, 09:03
Default Parallelization
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Any field data is only available at nodes, so, that part must be executed on nodes only, e.g., if you want to access pressure using F_P or C_P, use the code within

#if !RP_HOST
#endif

Do note ! before RP for negation.

File reading can be done by any node. If host does the reading, you have to transfer data to node using

host_to_node_transfer_#(var)

macros where # needs to be replaced by the type of data being transferred. To ensure that each node accesses only the cells and faces belonging to it, use _int loops, such as, begin_c_loop_int or begin_f_loop_int.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 22, 2020, 10:06
Default
  #3
New Member
 
Join Date: May 2020
Posts: 23
Rep Power: 5
Bibill is on a distinguished road
Thank you for your answer!

Then, since i do not access any solver/field data but i only read file and do some operations on the data from the text file i can do everything in HOST ?

A shortened version on my UDF is :


void cumulative_sum(float *cum_vector, float *signal, int size,int choice);


DEFINE_EXECUTE_AT_END(udf)
{

/* Import lift coefficient from txt file */

FILE* file_r;
file_r = fopen("cl.txt", "r");
if(file_r==NULL)
{
#if !RP_NODE
Message("\n");
Message("Error opening file \n");
Message(" \n");
#endif
}

float *signal;
signal = (float*)malloc(N_TIME*sizeof(float));
if ((signal==NULL))
{
#if !RP_NODE
Message("Memory allocation error \n");
#endif
}

int i;
for(i=0;i<N_TIME;i++)
{
fscanf(file_r, "%f",&f1);
signal[i] = f1;
}
fclose(file_r);
/* End import lift coefficient */

/* Computation of cummulative sum of C_l and cummulative sum of C_l^2*/
float *cum_x;
float *cum_squared;
cum_x = (float *)malloc((current_ts+1)*sizeof(float));
cum_squared = (float *)malloc((current_ts+1)*sizeof(float));
cumulative_sum(cum_x,signal,current_ts,0);
cumulative_sum(cum_squared,signal,current_ts,1);


...
}


where the auxilliary function cumulative_sum compute the cumsum of the signal for choice==0 and of the signal^2 for choice==1.
Bibill is offline   Reply With Quote

Old   June 22, 2020, 10:16
Default Only on Host
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
If you are doing everything on host, then put whole of the code within

#if !RP_NODE
#endif
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 22, 2020, 11:33
Default
  #5
New Member
 
Join Date: May 2020
Posts: 23
Rep Power: 5
Bibill is on a distinguished road
Even by doing everything on Host there are differences from the results with a C compiler and Fluent (it is exactly the same code)...

Do you have any common mistakes that i can investigate to fix it ?
Bibill is offline   Reply With Quote

Old   June 22, 2020, 11:41
Default The differences
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
What kind of differences do you observe?
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 22, 2020, 12:34
Default
  #7
New Member
 
Join Date: May 2020
Posts: 23
Rep Power: 5
Bibill is on a distinguished road
The purpose of my UDF is to estimate a parameter linked to the lift coefficient.

For it, i do some computations of descriptive statistics during the running time for the lift coefficient. It gives me a series of values. The parameter i want to estimate corresponds to the minimum of this series.

In the end, with the C compiler i obtain an increasing series e.g [13,15,15.5,30,35] and with Fluent i obtain basically the same series but with spurious 0 e.g [13,0,0,30,0].


Physically, a zero value makes no sense... It is thus due to how does Fluent treat the data. Moreover, when i print the values obtained by different nodes of computation for the same time it gives the right value (the one of the C compiler) for one or two nodes and 0 for the others...
Bibill is offline   Reply With Quote

Old   June 22, 2020, 22:55
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
input/output must be executed on host only

use Ansys Fluent Customization manual, it has detail explanation on parallelization process

next time put whole your code and full output from console.
By the way, it is good to define all your variables in the head of code not inside the code
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
parallelization, udf


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF for vapor pressure anuarun Fluent UDF and Scheme Programming 12 December 24, 2021 10:12
Save output of udf in another udf! JuanJoMex FLUENT 0 February 8, 2018 12:43
Replicating Scalable Wall Function with a UDF yousefaz FLUENT 0 August 4, 2017 02:30
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 04:01


All times are GMT -4. The time now is 08:37.