1112
for (phase_id = 0; phase_id < *nphas; phase_id++) {
1114
if ( *ivar == iu[phase_id]
1115
|| *ivar == iv[phase_id]
1116
|| *ivar == iw[phase_id]) {
1118
d_ph = stride2*phase_id;
1121
if (*ivar == iu[phase_id]) d_var = 0;
1122
if (*ivar == iv[phase_id]) d_var = n_ghost_cells;
1123
if (*ivar == iw[phase_id]) d_var = 2*n_ghost_cells;
1125
if (*iguper == 1) { /* dudxyz not computed */
1127
for (t_id = 0; t_id < n_transforms; t_id++) {
1129
shift = 4 * halo->n_c_domains * t_id;
1131
for (rank_id = 0; rank_id < halo->n_c_domains; rank_id++) {
1133
start_std = halo->perio_lst[shift + 4*rank_id];
1134
length = halo->perio_lst[shift + 4*rank_id + 1];
1135
end_std = start_std + length;
1137
if (mesh->halo_type == CS_HALO_EXTENDED) {
1139
start_ext = halo->perio_lst[shift + 4*rank_id + 2];
1140
length = halo->perio_lst[shift + 4*rank_id + 3];
1141
end_ext = start_ext + length;
1145
for (i = start_std; i < end_std; i++) {
1146
dpdx[n_cells + i] = dudxyz[i + d_var + stride1*0 + d_ph];
1147
dpdy[n_cells + i] = dudxyz[i + d_var + stride1*1 + d_ph];
1148
dpdz[n_cells + i] = dudxyz[i + d_var + stride1*2 + d_ph];
1151
if (mesh->halo_type == CS_HALO_EXTENDED) {
1153
for (i = start_ext; i < end_ext; i++) {
1154
dpdx[n_cells + i] = dudxyz[i + d_var + stride1*0 + d_ph];
1155
dpdy[n_cells + i] = dudxyz[i + d_var + stride1*1 + d_ph];
1156
dpdz[n_cells + i] = dudxyz[i + d_var + stride1*2 + d_ph];
1159
} /* End if extended halo */
1161
} /* End of loop on ranks */
1163
} /* End of loop on transformations */
1165
} /* End if *iguper == 1 */
1167
} /* If *ivar == iu or iv or iw */
1169
else if ((itytur[phase_id] == 3) &&
1170
(*ivar == ir11[phase_id] || *ivar == ir22[phase_id] ||
1171
*ivar == ir33[phase_id] || *ivar == ir12[phase_id] ||
1172
*ivar == ir13[phase_id] || *ivar == ir23[phase_id])) {
1174
d_ph = 2*stride2*phase_id;
1177
if (*ivar == ir11[phase_id]) d_var = 0;
1178
if (*ivar == ir22[phase_id]) d_var = n_ghost_cells;
1179
if (*ivar == ir33[phase_id]) d_var = 2*n_ghost_cells;
1180
if (*ivar == ir12[phase_id]) d_var = 3*n_ghost_cells;
1181
if (*ivar == ir13[phase_id]) d_var = 4*n_ghost_cells;
1182
if (*ivar == ir23[phase_id]) d_var = 5*n_ghost_cells;
1186
for (t_id = 0; t_id < n_transforms; t_id++) {
1188
shift = 4 * halo->n_c_domains * t_id;
1190
for (rank_id = 0; rank_id < halo->n_c_domains; rank_id++) {
1192
start_std = halo->perio_lst[shift + 4*rank_id];
1193
length = halo->perio_lst[shift + 4*rank_id + 1];
1194
end_std = start_std + length;
1196
if (mesh->halo_type == CS_HALO_EXTENDED) {
1198
start_ext = halo->perio_lst[shift + 4*rank_id + 2];
1199
length = halo->perio_lst[shift + 4*rank_id + 3];
1200
end_ext = start_ext + length;
1204
for (i = start_std; i < end_std; i++) {
1151
if (*ivar == *iu || *ivar == *iv || *ivar == *iw) {
1155
if (*ivar == *iu) d_var = 0;
1156
if (*ivar == *iv) d_var = n_ghost_cells;
1157
if (*ivar == *iw) d_var = 2*n_ghost_cells;
1159
if (*iguper == 1) { /* dudxyz not computed */
1161
for (t_id = 0; t_id < n_transforms; t_id++) {
1163
shift = 4 * halo->n_c_domains * t_id;
1165
for (rank_id = 0; rank_id < halo->n_c_domains; rank_id++) {
1167
start_std = halo->perio_lst[shift + 4*rank_id];
1168
length = halo->perio_lst[shift + 4*rank_id + 1];
1169
end_std = start_std + length;
1171
if (mesh->halo_type == CS_HALO_EXTENDED) {
1173
start_ext = halo->perio_lst[shift + 4*rank_id + 2];
1174
length = halo->perio_lst[shift + 4*rank_id + 3];
1175
end_ext = start_ext + length;
1179
for (i = start_std; i < end_std; i++) {
1180
dpdx[n_cells + i] = dudxyz[i + d_var + stride1*0];
1181
dpdy[n_cells + i] = dudxyz[i + d_var + stride1*1];
1182
dpdz[n_cells + i] = dudxyz[i + d_var + stride1*2];
1185
if (mesh->halo_type == CS_HALO_EXTENDED) {
1187
for (i = start_ext; i < end_ext; i++) {
1188
dpdx[n_cells + i] = dudxyz[i + d_var + stride1*0];
1189
dpdy[n_cells + i] = dudxyz[i + d_var + stride1*1];
1190
dpdz[n_cells + i] = dudxyz[i + d_var + stride1*2];
1193
} /* End if extended halo */
1195
} /* End of loop on ranks */
1197
} /* End of loop on transformations */
1199
} /* End if *iguper == 1 */
1201
} /* If *ivar == iu or iv or iw */
1203
else if ((*itytur == 3) &&
1204
(*ivar == *ir11 || *ivar == *ir22 ||
1205
*ivar == *ir33 || *ivar == *ir12 ||
1206
*ivar == *ir13 || *ivar == *ir23)) {
1210
if (*ivar == *ir11) d_var = 0;
1211
if (*ivar == *ir22) d_var = n_ghost_cells;
1212
if (*ivar == *ir33) d_var = 2*n_ghost_cells;
1213
if (*ivar == *ir12) d_var = 3*n_ghost_cells;
1214
if (*ivar == *ir13) d_var = 4*n_ghost_cells;
1215
if (*ivar == *ir23) d_var = 5*n_ghost_cells;
1219
for (t_id = 0; t_id < n_transforms; t_id++) {
1221
shift = 4 * halo->n_c_domains * t_id;
1223
for (rank_id = 0; rank_id < halo->n_c_domains; rank_id++) {
1225
start_std = halo->perio_lst[shift + 4*rank_id];
1226
length = halo->perio_lst[shift + 4*rank_id + 1];
1227
end_std = start_std + length;
1229
if (mesh->halo_type == CS_HALO_EXTENDED) {
1231
start_ext = halo->perio_lst[shift + 4*rank_id + 2];
1232
length = halo->perio_lst[shift + 4*rank_id + 3];
1233
end_ext = start_ext + length;
1237
for (i = start_std; i < end_std; i++) {
1238
dpdx[n_cells + i] = drdxyz[i + d_var + 2*stride1*0 + d_ph];
1239
dpdy[n_cells + i] = drdxyz[i + d_var + 2*stride1*1 + d_ph];
1240
dpdz[n_cells + i] = drdxyz[i + d_var + 2*stride1*2 + d_ph];
1243
if (mesh->halo_type == CS_HALO_EXTENDED) {
1245
for (i = start_ext; i < end_ext; i++) {
1205
1246
dpdx[n_cells + i] = drdxyz[i + d_var + 2*stride1*0 + d_ph];
1206
1247
dpdy[n_cells + i] = drdxyz[i + d_var + 2*stride1*1 + d_ph];
1207
1248
dpdz[n_cells + i] = drdxyz[i + d_var + 2*stride1*2 + d_ph];
1210
if (mesh->halo_type == CS_HALO_EXTENDED) {
1212
for (i = start_ext; i < end_ext; i++) {
1213
dpdx[n_cells + i] = drdxyz[i + d_var + 2*stride1*0 + d_ph];
1214
dpdy[n_cells + i] = drdxyz[i + d_var + 2*stride1*1 + d_ph];
1215
dpdz[n_cells + i] = drdxyz[i + d_var + 2*stride1*2 + d_ph];
1218
} /* End if extended halo */
1220
} /* End of loop on ranks */
1222
} /* End of loop on transformations */
1224
} /* End if *igrper == 1 */
1226
} /* If itytur[phase_id] == 3 and *ivar == irij */
1228
} /* End of loop on phases */
1251
} /* End if extended halo */
1253
} /* End of loop on ranks */
1255
} /* End of loop on transformations */
1257
} /* End if *igrper == 1 */
1259
} /* If *itytur == 3 and *ivar == irij */
1230
1261
if (tag == 1) {
2228
2316
/*----------------------------------------------------------------------------
2317
* Synchronize values for a real tensor (interleaved) between periodic cells.
2320
* halo <-> halo associated with variable to synchronize
2321
* sync_mode --> kind of halo treatment (standard or extended)
2322
* var <-> tensor to update
2323
*----------------------------------------------------------------------------*/
2326
cs_perio_sync_var_tens(const cs_halo_t *halo,
2327
cs_halo_type_t sync_mode,
2330
cs_int_t i, rank_id, shift, t_id;
2331
cs_int_t start_std = 0, end_std = 0, length = 0, start_ext = 0, end_ext = 0;
2332
cs_real_t v11, v12, v13, v21, v22, v23, v31, v32, v33;
2334
cs_real_t matrix[3][4];
2336
fvm_periodicity_type_t perio_type = FVM_PERIODICITY_NULL;
2338
const cs_int_t n_transforms = halo->n_transforms;
2339
const cs_int_t n_elts = halo->n_local_elts;
2340
const fvm_periodicity_t *periodicity = cs_glob_mesh->periodicity;
2342
if (sync_mode == CS_HALO_N_TYPES)
2345
assert(halo != NULL);
2347
_test_halo_compatibility(halo);
2349
for (t_id = 0; t_id < n_transforms; t_id++) {
2351
shift = 4 * halo->n_c_domains * t_id;
2353
perio_type = fvm_periodicity_get_type(periodicity, t_id);
2355
if (perio_type >= FVM_PERIODICITY_ROTATION) {
2357
fvm_periodicity_get_matrix(periodicity, t_id, matrix);
2359
for (rank_id = 0; rank_id < halo->n_c_domains; rank_id++) {
2361
start_std = halo->perio_lst[shift + 4*rank_id];
2362
length = halo->perio_lst[shift + 4*rank_id + 1];
2363
end_std = start_std + length;
2365
if (sync_mode == CS_HALO_EXTENDED) {
2367
start_ext = halo->perio_lst[shift + 4*rank_id + 2];
2368
length = halo->perio_lst[shift + 4*rank_id + 3];
2369
end_ext = start_ext + length;
2373
for (i = start_std; i < end_std; i++) {
2375
v11 = var[0 + 3*0 + 9*(n_elts + i)];
2376
v12 = var[0 + 3*1 + 9*(n_elts + i)];
2377
v13 = var[0 + 3*2 + 9*(n_elts + i)];
2378
v21 = var[1 + 3*0 + 9*(n_elts + i)];
2379
v22 = var[1 + 3*1 + 9*(n_elts + i)];
2380
v23 = var[1 + 3*2 + 9*(n_elts + i)];
2381
v31 = var[2 + 3*0 + 9*(n_elts + i)];
2382
v32 = var[2 + 3*1 + 9*(n_elts + i)];
2383
v33 = var[2 + 3*2 + 9*(n_elts + i)];
2385
_apply_tensor_rotation(matrix,
2386
v11, v12, v13, v21, v22, v23,
2388
&var[0 + 3*0 + 9*(n_elts + i)],
2389
&var[0 + 3*1 + 9*(n_elts + i)],
2390
&var[0 + 3*2 + 9*(n_elts + i)],
2391
&var[1 + 3*0 + 9*(n_elts + i)],
2392
&var[1 + 3*1 + 9*(n_elts + i)],
2393
&var[1 + 3*2 + 9*(n_elts + i)],
2394
&var[2 + 3*0 + 9*(n_elts + i)],
2395
&var[2 + 3*1 + 9*(n_elts + i)],
2396
&var[2 + 3*2 + 9*(n_elts + i)]);
2400
if (sync_mode == CS_HALO_EXTENDED) {
2402
for (i = start_ext; i < end_ext; i++) {
2404
v11 = var[0 + 3*0 + 9*(n_elts + i)];
2405
v12 = var[0 + 3*1 + 9*(n_elts + i)];
2406
v13 = var[0 + 3*2 + 9*(n_elts + i)];
2407
v21 = var[1 + 3*0 + 9*(n_elts + i)];
2408
v22 = var[1 + 3*1 + 9*(n_elts + i)];
2409
v23 = var[1 + 3*2 + 9*(n_elts + i)];
2410
v31 = var[2 + 3*0 + 9*(n_elts + i)];
2411
v32 = var[2 + 3*1 + 9*(n_elts + i)];
2412
v33 = var[2 + 3*2 + 9*(n_elts + i)];
2414
_apply_tensor_rotation(matrix,
2415
v11, v12, v13, v21, v22, v23,
2417
&var[0 + 3*0 + 9*(n_elts + i)],
2418
&var[0 + 3*1 + 9*(n_elts + i)],
2419
&var[0 + 3*2 + 9*(n_elts + i)],
2420
&var[1 + 3*0 + 9*(n_elts + i)],
2421
&var[1 + 3*1 + 9*(n_elts + i)],
2422
&var[1 + 3*2 + 9*(n_elts + i)],
2423
&var[2 + 3*0 + 9*(n_elts + i)],
2424
&var[2 + 3*1 + 9*(n_elts + i)],
2425
&var[2 + 3*2 + 9*(n_elts + i)]);
2429
} /* End of the treatment of rotation */
2431
} /* End if halo is extended */
2433
} /* End of loop on ranks */
2435
} /* End of loop on transformations for the local rank */
2438
/*----------------------------------------------------------------------------
2229
2439
* Synchronize values for a real diagonal tensor between periodic cells.
2231
2441
* We only know the diagonal of the tensor.
2333
2543
/*----------------------------------------------------------------------------
2544
* Synchronize values for a real diagonal tensor (interleaved)
2545
* between periodic cells.
2547
* We only know the interleaved diagonal of the tensor.
2550
* halo <-> halo associated with variable to synchronize
2551
* sync_mode --> kind of halo treatment (standard or extended)
2552
* var <-> diagonal tensor to update
2553
*----------------------------------------------------------------------------*/
2556
cs_perio_sync_var_diag(const cs_halo_t *halo,
2557
cs_halo_type_t sync_mode,
2560
cs_int_t i, rank_id, shift, t_id;
2561
cs_int_t start_std = 0, end_std = 0, length = 0, start_ext = 0, end_ext = 0;
2562
cs_real_t v11, v22, v33;
2563
cs_real_t matrix[3][4];
2565
fvm_periodicity_type_t perio_type = FVM_PERIODICITY_NULL;
2567
const cs_int_t n_transforms = halo->n_transforms;
2568
const cs_int_t n_elts = halo->n_local_elts;
2569
const fvm_periodicity_t *periodicity = cs_glob_mesh->periodicity;
2571
if (sync_mode == CS_HALO_N_TYPES)
2574
assert(halo != NULL);
2576
_test_halo_compatibility(halo);
2578
for (t_id = 0; t_id < n_transforms; t_id++) {
2580
shift = 4 * halo->n_c_domains * t_id;
2582
perio_type = fvm_periodicity_get_type(periodicity, t_id);
2584
if (perio_type >= FVM_PERIODICITY_ROTATION) {
2586
fvm_periodicity_get_matrix(periodicity, t_id, matrix);
2588
for (rank_id = 0; rank_id < halo->n_c_domains; rank_id++) {
2590
start_std = halo->perio_lst[shift + 4*rank_id];
2591
length = halo->perio_lst[shift + 4*rank_id + 1];
2592
end_std = start_std + length;
2594
if (sync_mode == CS_HALO_EXTENDED) {
2596
start_ext = halo->perio_lst[shift + 4*rank_id + 2];
2597
length = halo->perio_lst[shift + 4*rank_id + 3];
2598
end_ext = start_ext + length;
2602
for (i = start_std; i < end_std; i++) {
2604
v11 = var[0 + 3*(n_elts + i)];
2605
v22 = var[1 + 3*(n_elts + i)];
2606
v33 = var[2 + 3*(n_elts + i)];
2608
_apply_tensor_rotation(matrix,
2609
v11, 0, 0, 0, v22, 0,
2611
&var[0 + 3*(n_elts + i)],
2615
&var[1 + 3*(n_elts + i)],
2619
&var[2 + 3*(n_elts + i)]);
2623
if (sync_mode == CS_HALO_EXTENDED) {
2625
for (i = start_ext; i < end_ext; i++) {
2627
v11 = var[0 + 3*(n_elts + i)];
2628
v22 = var[1 + 3*(n_elts + i)];
2629
v33 = var[2 + 3*(n_elts + i)];
2631
_apply_tensor_rotation(matrix,
2632
v11, 0, 0, 0, v22, 0,
2634
&var[0 + 3*(n_elts + i)],
2638
&var[1 + 3*(n_elts + i)],
2642
&var[2 + 3*(n_elts + i)]);
2646
} /* End if halo is extended */
2648
} /* End of loop on ranks */
2650
} /* End of the treatment of rotation */
2652
} /* End of loop on transformations */
2654
/*----------------------------------------------------------------------------
2334
2655
* Update global halo backup buffer size so as to be usable with a given halo.
2336
2657
* This function should be called at the end of any halo creation,
2570
2891
return restore_count;
2573
/*----------------------------------------------------------------------------
2574
* Define parameters for building an interface set structure on the main mesh.
2577
* p_n_periodic_lists <-> pointer to the number of periodic lists (may
2579
* p_periodic_num <-> pointer to the periodicity number (1 to n)
2580
* associated with each periodic list (primary
2581
* periodicities only)
2582
* p_n_periodic_couples <-> pointer to the number of periodic couples
2583
* p_periodic_couples <-> pointer to the periodic couple list
2584
*----------------------------------------------------------------------------*/
2587
cs_perio_define_couples(int *p_n_periodic_lists,
2588
int *p_periodic_num[],
2589
fvm_lnum_t *p_n_periodic_couples[],
2590
fvm_gnum_t **p_periodic_couples[])
2592
cs_int_t i, j, k, n_elts;
2593
cs_int_t face_rank, perio_id, rank_id, fac_id, fac_num;
2594
cs_int_t shift_key, shift_key_couple, rshift, sshift;
2596
cs_int_t n_max_face_vertices = 0, n_face_vertices = 0;
2597
cs_int_t *send_count = NULL, *recv_count = NULL;
2598
cs_int_t *send_shift = NULL, *recv_shift = NULL;
2599
cs_int_t *send_rank_count = NULL, *recv_rank_count = NULL;
2600
cs_int_t *send_rank_shift = NULL, *recv_rank_shift = NULL;
2601
cs_int_t *perio_couple_count = NULL, *perio_couple_shift = NULL;
2602
fvm_gnum_t *send_buffer = NULL, *recv_buffer = NULL;
2603
fvm_gnum_t *f1_vertices = NULL, *f2_vertices = NULL;
2605
int *periodic_num = NULL;
2606
fvm_lnum_t *n_periodic_couples = NULL;
2607
fvm_gnum_t **periodic_couples = NULL;
2609
const cs_int_t n_ranks = cs_glob_mesh->n_domains;
2610
const cs_int_t n_perio = cs_glob_mesh->n_init_perio;
2611
const cs_int_t n_keys = n_ranks * n_perio;
2612
const cs_int_t local_rank = (cs_glob_rank_id == -1) ? 0:cs_glob_rank_id;
2613
const cs_int_t *per_face_idx = cs_glob_mesh_builder->per_face_idx;
2614
const cs_int_t *per_face_lst = cs_glob_mesh_builder->per_face_lst;
2615
const cs_int_t *per_rank_lst = cs_glob_mesh_builder->per_rank_lst;
2616
const cs_int_t *face_vtx_idx = cs_glob_mesh->i_face_vtx_idx;
2617
const cs_int_t *face_vtx_lst = cs_glob_mesh->i_face_vtx_lst;
2618
const fvm_gnum_t *g_vtx_num = cs_glob_mesh->global_vtx_num;
2620
/* Allocate and initialize buffers */
2622
BFT_MALLOC(send_count, n_keys, cs_int_t);
2623
BFT_MALLOC(recv_count, n_keys, cs_int_t);
2624
BFT_MALLOC(perio_couple_count, n_keys, cs_int_t);
2625
BFT_MALLOC(send_shift, n_keys + 1, cs_int_t);
2626
BFT_MALLOC(recv_shift, n_keys + 1, cs_int_t);
2627
BFT_MALLOC(perio_couple_shift, n_keys + 1, cs_int_t);
2629
for (i = 0; i < n_keys; i++) {
2634
perio_couple_count[i] = 0;
2635
perio_couple_shift[i] = 0;
2638
send_shift[n_keys] = 0;
2639
recv_shift[n_keys] = 0;
2640
perio_couple_shift[n_keys] = 0;
2642
/* First step: count number of elements to send */
2644
for (perio_id = 0; perio_id < n_perio; perio_id++) {
2647
The buffer per_face_lst is composed by pairs of face.
2648
The first element is the local number of the local face. The sign of the
2649
face indicates the sign of the periodicty.
2650
The second element is the local number of the distant face.
2651
The buffer per_rank_lst owns for each distant face the rank id of the
2652
distant rank associated to the face.
2655
for (i = per_face_idx[perio_id]; i < per_face_idx[perio_id + 1]; i++) {
2657
fac_num = per_face_lst[2*i];
2658
fac_id = CS_ABS(fac_num) - 1;
2659
n_face_vertices = face_vtx_idx[fac_id+1] - face_vtx_idx[fac_id];
2660
n_max_face_vertices = CS_MAX(n_max_face_vertices, n_face_vertices);
2662
assert(fac_num != 0);
2665
face_rank = per_rank_lst[i] - 1;
2669
shift_key = n_perio*face_rank + perio_id;
2671
if (local_rank == face_rank)
2672
send_count[shift_key] += n_face_vertices;
2676
send_count[shift_key] += n_face_vertices;
2678
} /* End of loop on couples */
2680
} /* End of loop on periodicities */
2682
/* Exchange number of elements to exchange */
2684
#if defined(HAVE_MPI)
2686
MPI_Alltoall(send_count, n_perio, CS_MPI_INT,
2687
recv_count, n_perio, CS_MPI_INT, cs_glob_mpi_comm);
2691
for (i = 0; i < n_keys; i++)
2692
recv_count[i] = send_count[i];
2694
/* Build perio_couple_count from recv_count */
2696
for (rank_id = 0; rank_id < n_ranks; rank_id++)
2697
for (perio_id = 0; perio_id < n_perio; perio_id++)
2698
perio_couple_count[n_ranks*perio_id+rank_id]
2699
= recv_count[n_perio*rank_id+perio_id];
2703
for (i = 0; i < n_keys; i++) {
2705
recv_shift[i+1] = recv_shift[i] + recv_count[i];
2706
send_shift[i+1] = send_shift[i] + send_count[i];
2707
perio_couple_shift[i+1] = perio_couple_shift[i] + perio_couple_count[i];
2711
assert(perio_couple_shift[n_keys] == recv_shift[n_keys]);
2713
/* Allocate and initialize buffers for building periodic interface set */
2715
BFT_MALLOC(periodic_num, n_perio, int);
2716
BFT_MALLOC(n_periodic_couples, n_perio, fvm_lnum_t);
2717
BFT_MALLOC(periodic_couples, n_perio, fvm_gnum_t *);
2719
for (perio_id = 0; perio_id < n_perio; perio_id++) {
2721
periodic_num[perio_id] = perio_id+1;
2722
n_periodic_couples[perio_id] = 0;
2723
periodic_couples[perio_id] = NULL;
2725
for (rank_id = 0; rank_id < n_ranks; rank_id++)
2726
n_periodic_couples[perio_id] +=
2727
perio_couple_count[n_ranks*perio_id + rank_id];
2729
BFT_MALLOC(periodic_couples[perio_id],
2730
2*n_periodic_couples[perio_id],
2733
} /* End of loop on periodicities */
2735
/* Build send buffer and the first part of the periodic couples
2736
in global numbering */
2738
BFT_MALLOC(send_buffer, send_shift[n_keys], fvm_gnum_t);
2739
BFT_MALLOC(recv_buffer, recv_shift[n_keys], fvm_gnum_t);
2740
BFT_MALLOC(f1_vertices, n_max_face_vertices, fvm_gnum_t);
2741
BFT_MALLOC(f2_vertices, n_max_face_vertices, fvm_gnum_t);
2743
for (i = 0; i < n_keys; i++) {
2745
perio_couple_count[i] = 0;
2748
/* Second step: Fill send_buffer and first part of periodic_couples */
2750
for (perio_id = 0; perio_id < n_perio; perio_id++) {
2752
fvm_gnum_t *_periodic_couples = periodic_couples[perio_id];
2754
for (i = per_face_idx[perio_id]; i < per_face_idx[perio_id+1]; i++) {
2756
fac_num = per_face_lst[2*i];
2757
fac_id = CS_ABS(fac_num) - 1;
2758
n_face_vertices = face_vtx_idx[fac_id+1] - face_vtx_idx[fac_id];
2761
face_rank = per_rank_lst[i] - 1;
2765
shift_key = n_perio*face_rank + perio_id;
2766
shift_key_couple = n_ranks*perio_id + face_rank;
2768
sshift = send_count[shift_key] + send_shift[shift_key];
2769
rshift = perio_couple_count[shift_key_couple]
2770
+ perio_couple_shift[shift_key_couple]
2771
- perio_couple_shift[n_ranks*perio_id];
2775
for (k= 0, j = face_vtx_idx[fac_id]-1;
2776
j < face_vtx_idx[fac_id+1]-1; j++, k++) {
2777
if (g_vtx_num != NULL)
2778
f1_vertices[k] = (fvm_gnum_t)g_vtx_num[face_vtx_lst[j]-1];
2780
f1_vertices[k] = (fvm_gnum_t)face_vtx_lst[j];
2783
if (local_rank == face_rank) {
2787
fac_id = CS_ABS(per_face_lst[2*i+1]) - 1;
2789
for (k= 0, j = face_vtx_idx[fac_id]-1;
2790
j < face_vtx_idx[fac_id+1]-1; j++, k++) {
2791
if (g_vtx_num != NULL)
2792
f2_vertices[k] = (fvm_gnum_t)g_vtx_num[face_vtx_lst[j]-1];
2794
f2_vertices[k] = (fvm_gnum_t)face_vtx_lst[j];
2799
if (fac_num < 0) { /* Send f1 and copy f2 in periodic_couples */
2801
for (k = 0; k < n_face_vertices; k++)
2802
send_buffer[sshift + k] = f1_vertices[k];
2804
for (k = 0; k < n_face_vertices; k++)
2805
_periodic_couples[2*(rshift + k)] = f2_vertices[k];
2808
else { /* Send f2 and copy f1 in periodic couples */
2810
for (k = 0; k < n_face_vertices; k++)
2811
send_buffer[sshift + k] = f2_vertices[k];
2813
for (k = 0; k < n_face_vertices; k++)
2814
_periodic_couples[2*(rshift + k)] = f1_vertices[k];
2818
send_count[shift_key] += n_face_vertices;
2819
perio_couple_count[shift_key_couple] += n_face_vertices;
2822
else { /* local_rank != face_rank */
2824
if (fac_num < 0) { /* Fill send_buffer with f1 */
2826
for (k = 0; k < n_face_vertices; k++)
2827
send_buffer[sshift + k] = f1_vertices[k];
2829
send_count[shift_key] += n_face_vertices;
2832
else { /* Fill _periodic_couples with f1 */
2834
for (k = 0; k < n_face_vertices; k++)
2835
_periodic_couples[2*(rshift + k)] = f1_vertices[k];
2837
perio_couple_count[shift_key_couple] += n_face_vertices;
2841
} /* Face_rank != local_rank */
2843
} /* End of loop on couples */
2845
} /* End of loop on periodicity */
2847
/* Exchange buffers */
2851
/* count and shift on ranks for MPI_Alltoallv */
2853
BFT_MALLOC(send_rank_count, n_ranks, cs_int_t);
2854
BFT_MALLOC(recv_rank_count, n_ranks, cs_int_t);
2855
BFT_MALLOC(send_rank_shift, n_ranks, cs_int_t);
2856
BFT_MALLOC(recv_rank_shift, n_ranks, cs_int_t);
2858
for (i = 0; i < n_ranks; i++) {
2860
send_rank_count[i] = 0;
2861
recv_rank_count[i] = 0;
2863
for (perio_id = 0; perio_id < n_perio; perio_id++) {
2865
send_rank_count[i] += send_count[n_perio*i + perio_id];
2866
recv_rank_count[i] += recv_count[n_perio*i + perio_id];
2868
} /* End of loop on periodicities */
2870
} /* End of loop on ranks */
2872
send_rank_shift[0] = 0;
2873
recv_rank_shift[0] = 0;
2875
for (i = 0; i < n_ranks - 1; i++) {
2877
send_rank_shift[i+1] = send_rank_shift[i] + send_rank_count[i];
2878
recv_rank_shift[i+1] = recv_rank_shift[i] + recv_rank_count[i];
2880
} /* End of loop on ranks */
2882
#if 0 && defined(DEBUG) && !defined(NDEBUG) /* DEBUG */
2883
for (rank_id = 0; rank_id < n_ranks; rank_id++) {
2884
bft_printf("RANK_ID: %d - send_count: %d - send_shift: %d\n",
2885
rank_id, send_rank_count[rank_id],
2886
send_rank_shift[rank_id]);
2887
for (i = 0; i < send_rank_count[rank_id]; i++)
2888
bft_printf("\t%5d | %8d | %12u\n",
2889
i, i + send_rank_shift[rank_id],
2890
send_buffer[i + send_rank_shift[rank_id]]);
2895
#if defined(HAVE_MPI)
2896
MPI_Alltoallv(send_buffer, send_rank_count, send_rank_shift, FVM_MPI_GNUM,
2897
recv_buffer, recv_rank_count, recv_rank_shift, FVM_MPI_GNUM,
2901
#if 0 && defined(DEBUG) && !defined(NDEBUG) /* DEBUG */
2902
for (rank_id = 0; rank_id < n_ranks; rank_id++) {
2904
bft_printf("RANK_ID: %d - recv_count: %d - recv_shift: %d\n",
2905
rank_id, recv_rank_count[rank_id],
2906
recv_rank_shift[rank_id]);
2907
for (i = 0; i < recv_rank_count[rank_id]; i++)
2908
bft_printf("\t%5d | %8d | %12u\n",
2909
i, i + recv_rank_shift[rank_id],
2910
recv_buffer[i + recv_rank_shift[rank_id]]);
2915
BFT_FREE(send_rank_count);
2916
BFT_FREE(recv_rank_count);
2917
BFT_FREE(send_rank_shift);
2918
BFT_FREE(recv_rank_shift);
2920
} /* End if n_ranks > 1 */
2924
assert(n_ranks == 1);
2925
assert(send_shift[n_keys] == recv_shift[n_keys]);
2927
for (i = 0; i < send_shift[n_keys]; i++)
2928
recv_buffer[i] = send_buffer[i];
2932
/* Memory management */
2934
BFT_FREE(send_count);
2935
BFT_FREE(send_shift);
2936
BFT_FREE(send_buffer);
2937
BFT_FREE(f1_vertices);
2938
BFT_FREE(f2_vertices);
2940
/* Finalize periodic couples definition in the global numbering */
2942
for (perio_id = 0; perio_id < n_perio; perio_id++) {
2944
fvm_gnum_t *_periodic_couples = periodic_couples[perio_id];
2946
for (rank_id = 0; rank_id < n_ranks; rank_id++) {
2948
shift_key = n_perio*rank_id + perio_id;
2949
shift_key_couple = n_ranks*perio_id + rank_id;
2951
assert(recv_count[shift_key] == perio_couple_count[shift_key_couple]);
2952
n_elts = recv_count[shift_key];
2954
sshift = perio_couple_shift[shift_key_couple]
2955
- perio_couple_shift[n_ranks*perio_id];
2956
rshift = recv_shift[shift_key];
2959
bft_printf("\nPERIO: %d - RANK: %d - N_ELTS: %d\n",
2960
perio_id, rank_id, n_elts);
2961
bft_printf("shift_key: %d, shift_key_couple: %d\n",
2962
shift_key, shift_key_couple);
2963
bft_printf("SSHIFT: %d - RSHIFT: %d\n", sshift, rshift);
2967
for (j = 0; j < n_elts; j++)
2968
_periodic_couples[2*sshift + 2*j+1] = recv_buffer[rshift + j];
2970
} /* End of loop on ranks */
2972
} /* End of loop on periodicities */
2974
BFT_FREE(recv_count);
2975
BFT_FREE(recv_shift);
2976
BFT_FREE(recv_buffer);
2977
BFT_FREE(perio_couple_count);
2978
BFT_FREE(perio_couple_shift);
2980
/* Values to return. Assign pointers */
2982
*p_n_periodic_lists = n_perio;
2983
*p_periodic_num = periodic_num;
2984
*p_n_periodic_couples = n_periodic_couples;
2985
*p_periodic_couples = periodic_couples;
2988
for (i = 0; i < n_perio; i++) {
2990
bft_printf("\n\n Periodicity number: %d\n", periodic_num[i]);
2991
bft_printf(" Number of couples : %d\n", n_periodic_couples[i]);
2992
for (j = 0; j < n_periodic_couples[i]; j++)
2993
bft_printf("%12d --> %12d\n",
2994
periodic_couples[i][2*j], periodic_couples[i][2*j + 1]);
3000
2894
/*----------------------------------------------------------------------------*/