|
[Sponsors] |
June 22, 2020, 09:30 |
UDF Parallelization
|
#1 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
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! |
|
June 22, 2020, 10:03 |
Parallelization
|
#2 |
Senior Member
|
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. |
|
June 22, 2020, 11:06 |
|
#3 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
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. |
|
June 22, 2020, 11:16 |
Only on Host
|
#4 |
Senior Member
|
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. |
|
June 22, 2020, 12:33 |
|
#5 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
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 ? |
|
June 22, 2020, 12:41 |
The differences
|
#6 |
Senior Member
|
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. |
|
June 22, 2020, 13:34 |
|
#7 |
New Member
Join Date: May 2020
Posts: 23
Rep Power: 6 |
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... |
|
June 22, 2020, 23:55 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 |
|
Tags |
parallelization, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF for vapor pressure | anuarun | Fluent UDF and Scheme Programming | 13 | June 23, 2024 14:12 |
Save output of udf in another udf! | JuanJoMex | FLUENT | 0 | February 8, 2018 13:43 |
Replicating Scalable Wall Function with a UDF | yousefaz | FLUENT | 0 | August 4, 2017 03:30 |
UDF parallel error: chip-exec: function not found????? | shankara.2 | Fluent UDF and Scheme Programming | 1 | January 16, 2012 23:14 |
UDF, UDF, UDF, UDF | Luc SEMINEL | Main CFD Forum | 0 | November 25, 2002 05:01 |