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);
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);
Example 3
Sum of a real 'rrr', here the volume.
bft_printf(
"%s: total domain volume = %14.5e\n", __func__, rrr);
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);
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]);
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]);
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]);
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]);
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]);
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]);