We’re putting the final touches on our new badges platform. Badge issuance remains temporarily paused, but all completions are being recorded and will be fulfilled once the platform is live. Thank you for your patience.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Fluent UDF: An example using PRF_GRSUM macro?

    • Mehdi Famouri
      Subscriber

      Hello fellow UDF writers! Does anyone have an example using PRF_GRSUM macro? Please note, I'm not asking about PRF_GRSUM1 macro. 

      Best,
      Mehdi

    • Luca B.
      Forum Moderator

      Hi,

      The PRF_GRSUM macro in Fluent's User Defined Functions (UDF) is used to compute the global sum of a float or double array across all compute nodes in a parallel computation. Here's an example of how you might use the PRF_GRSUM macro in a UDF:

      DEFINE_ON_DEMAND(test)

      {

      real x[1]; /* Array of size 1 to hold the sum */

      real sum;

      int iwork[1]; /* Work array for parallel operation */

      /* Initialize the array with the value to sum */

      x[0] = 5; /* Your code to set the initial value */

      /* Compute the global sum */

      PRF_GRSUM(x, 1, iwork);

      /* x[0] now contains the sum of the values across all compute nodes */

      sum = x[0];

      Message0("Total = %f\n",sum);

      /* You can now use 'sum' for further calculations or monitoring */

      }

      In this example, x is an array that you want to sum across all compute nodes. The PRF_GRSUM macro takes the array x, the number of elements in the array (which is 1 in this case), and a work array iwork as arguments. After the macro is called, x[0] will contain the global sum of the values that were in x on each compute node.

      Please note that the PRF_GRSUM macro should be used in a context where it is called only once per compute node, such as within the DEFINE_ADJUST macro, to avoid issues with parallel execution as mentioned in the documentation.

    • Mehdi Famouri
      Subscriber

      Thank you Luca for your attention and reply, shouldn't "x" and "iwork" have the same declaration? One is integer and the other is real. 

    • Mehdi Famouri
      Subscriber

      Here is an example:

       

       

       

      https://www.scribd.com/document/385779402/UDF-Mechanics

      Page 38-39

Viewing 3 reply threads
  • The topic ‘Fluent UDF: An example using PRF_GRSUM macro?’ is closed to new replies.