Parallel operations
This is an example of cs_user_extra_operations which performs parallel operations.
Example 1
Sum of an integer counter 'ii', here the number of cells.
 
 
  bft_printf(
"%s: total number of cells = %ld\n", __func__, (
long)g_ii);
 
int bft_printf(const char *const format,...)
Replacement for printf() with modifiable behavior.
Definition: bft_printf.c:140
#define CS_GNUM_TYPE
Definition: cs_defs.h:437
unsigned long cs_gnum_t
global mesh entity number
Definition: cs_defs.h:310
static void cs_parall_sum(int n, cs_datatype_t datatype, void *val)
Sum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:154
  
Example 2
Maximum of an integer counter 'ii', here the number of cells.
 
 
  bft_printf(
"%s: max. number of cells per rank = %d\n", __func__, ii);
 
#define CS_LNUM_TYPE
Definition: cs_defs.h:454
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
static void cs_parall_max(int n, cs_datatype_t datatype, void *val)
Maximum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:191
  
Example 3
Sum of a real 'rrr', here the volume.
 
 
  bft_printf(
"%s: total domain volume = %14.5e\n", __func__, rrr);
 
double cs_sum(cs_lnum_t n, const cs_real_t *x)
Definition: cs_blas.c:1382
double cs_real_t
Floating-point value.
Definition: cs_defs.h:332
#define CS_REAL_TYPE
Definition: cs_defs.h:472
  
Example 4
Minimum of a real 'rrr', here the volume.
  rrr = 0;
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
    if (rrr < cell_vol[c_id])
      rrr = cell_vol[c_id];
  }
 
 
  bft_printf(
"%s: max cell volume = %14.5e\n", __func__, rrr);
 
Example 5
Maximum of a real 'rrr', here the volume.
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
    if (rrr > cell_vol[c_id])
      rrr = cell_vol[c_id];
  }
 
 
  bft_printf(
"%s: min cell volume = %14.5e\n", __func__, rrr);
 
const cs_real_t cs_math_big_r
static void cs_parall_min(int n, cs_datatype_t datatype, void *val)
Minimum values of a given datatype on all default communicator processes.
Definition: cs_parall.h:228
  
Example 6
Maximum of a real and associated real values; here the volume and its location (3 coordinates).
  rrr = -1;
 
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
    if (rrr < cell_vol[c_id]) {
      rrr = cell_vol[c_id];
      for (int i = 0; i < 3; i++)
        xyz[i] = cell_cen[c_id][i];
    }
  }
 
 
  bft_printf(
"%s: Max. volume = %14.5e.\n", __func__, rrr);
 
  bft_printf(
"Location(x,y,z) = %14.5e, %14.5e, %14.5e\n",
 
             xyz[0], xyz[1], xyz[2]);
void cs_parall_max_loc_vals(int n, cs_real_t *max, cs_real_t max_loc_vals[])
Maximum value of a real and the value of related array on all default communicator processes.
Definition: cs_parall.c:764
Example 7
Minimum of a real and associated real values; here the volume and its location (3 coordinates).
  rrr = 1e30;
  xyz[0] = 0;
  xyz[1] = 0;
  xyz[2] = 0;
 
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
    if (rrr > cell_vol[c_id]) {
      rrr = cell_vol[c_id];
      for (int i = 0; i < 3; i++)
        xyz[i] = cell_cen[c_id][i];
    }
  }
 
 
  bft_printf(
"%s: Min. volume = %14.5e.\n ", __func__, rrr);
 
  bft_printf(
"           Location (x,y,z) = %14.5e, %14.5e, %14.5e\n",
 
             xyz[0], xyz[1], xyz[2]);
void cs_parall_min_loc_vals(int n, cs_real_t *min, cs_real_t min_loc_vals[])
Minimum value of a real and the value of related array on all default communicator processes.
Definition: cs_parall.c:802
Example 8
Sum of an array of integers; here, the number of cells, faces, and boundary faces.
local values; note that to avoid counting interior faces on parallel boundaries twice, we check if 'ifacel(1,ifac) .le. ncel', as on a parallel boundary, this is always true for one domain and false for the other.
  cs_gnum_t g_itab[3] = {n_cells, 0, n_b_faces};
 
 
  for (
cs_lnum_t f_id = 0; f_id < n_i_faces; f_id++)
 
    if (i_face_cells[f_id][0] <= n_cells)
      g_itab[1]++;
 
 
             "Number of cells = %ld\n"
             "Number of interior faces = %ld\n"
             "Number of boundary faces = %ld\n\n",
             __func__, (long)g_itab[0], (long)g_itab[1], (long)g_itab[2]);
Example 9
Maxima from an array of integers; here, the number of cells, faces, and boundary faces.
  itab[0] = n_cells;
  itab[1] = n_i_faces;
  itab[2] = n_b_faces;
 
  
 
             " Max. number of cells per rank = %d\n"
             " Max. number of interior faces per rank = %d\n"
             " Max. number of boundary faces per rank = %d\n\n",
             __func__, (int)itab[0], (int)itab[1], (int)itab[2]);
 
 
Example 10
Minima from an array of integers; here, the number of cells, faces, and boundary faces.
  itab[0] = n_cells;
  itab[1] = n_i_faces;
  itab[2] = n_b_faces;
 
  
 
             " Min. number of cells per rank = %d\n"
             " Min. number of interior faces per rank = %d\n"
             " Min. number of boundary faces per rank = %d\n\n",
             __func__, (int)itab[0], (int)itab[1], (int)itab[2]);
Example 11
Sum of an array of reals; here, the 3 velocity components (so as to compute a mean for example).
  xyz[0] = 0;
  xyz[1] = 0;
  xyz[2] = 0;
 
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
      xyz[i] += cvar_vel[c_id][i];
  }
 
  
 
             " Sum of U on the domain = %14.5e\n"
             " Sum of V on the domain = %14.5e\n"
             " Sum of V on the domain = %14.5e\n\n",
             __func__, xyz[0], xyz[1], xyz[2]);
Example 12
Maximum of an array of reals; here, the 3 velocity components.
  xyz[0] = cvar_vel[0][0];
  xyz[1] = cvar_vel[0][1];
  xyz[2] = cvar_vel[0][2];
 
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
  }
 
  
 
             " Max. of U on the domain = %14.5e\n"
             " Max. of V on the domain = %14.5e\n"
             " Max. of V on the domain = %14.5e\n\n",
             __func__, xyz[0], xyz[1], xyz[2]);
static CS_F_HOST_DEVICE cs_real_t cs_math_fmax(cs_real_t x, cs_real_t y)
Compute the max value of two real values.
Definition: cs_math.h:200
Example 13
Maximum of an array of reals; here, the 3 velocity components.
  xyz[0] = cvar_vel[0][0];
  xyz[1] = cvar_vel[0][1];
  xyz[2] = cvar_vel[0][2];
 
  for (
cs_lnum_t c_id = 0; c_id < n_cells; c_id++) {
 
    for (int i = 0; i < 3; i++)
  }
 
  
 
             " Min. of U on the domain = %14.5e\n"
             " Min. of V on the domain = %14.5e\n"
             " Min. of V on the domain = %14.5e\n\n",
             __func__, xyz[0], xyz[1], xyz[2]);
static CS_F_HOST_DEVICE cs_real_t cs_math_fmin(cs_real_t x, cs_real_t y)
Compute the min value of two real values.
Definition: cs_math.h:181
Example 14
Broadcast an array of local integers to other ranks; in this example, we use the number of cells, interior faces, and boundary faces from process rank 0 (root_rank).
  int root_rank = 0;
  itab[0] = n_cells;
  itab[1] = n_i_faces;
  itab[2] = n_b_faces;
 
  
 
             "              Number of cells          = %d\n"
             "              Number of interior faces = %d\n"
             "              Number of boundary faces = %d\n\n",
             __func__, root_rank, (int)itab[0], (int)itab[1], (int)itab[2]);
static void cs_parall_bcast(int root_rank, int n, cs_datatype_t datatype, void *val)
Broadcast values of a given datatype to all default communicator processes.
Definition: cs_parall.h:267
Example 15
Broadcast an array of local reals to other ranks; in this example, we use 3 velocity values from process rank 0 (root_rank).
  xyz[0] = cvar_vel[0][0];
  xyz[1] = cvar_vel[0][1];
  xyz[2] = cvar_vel[0][2];
 
  
 
             "          Velocity U in first cell = %14.5e\n"
             "          Velocity V in first cell = %14.5e\n"
             "          Velocity W in first cell = %14.5e\n\n",
             __func__, root_rank, xyz[0], xyz[1], xyz[2]);