28 #define MAX_NODE_SIZE 20
30 #define INFINITE (1.0E+37)
82 static void free_link_list(
struct link_list *r) {
106 static struct map_info *alloc_struct_map_info(
void) {
124 static void free_struct_map_info(
struct map_info *p) {
125 if (p ==
NULL)
return;
137 if (p ==
NULL)
return;
177 fprintf(fp,
"*** Interface Table for Inter-communication\n");
179 fprintf(fp,
"number of neighbor processes for import: %d\n",
181 fprintf(fp,
"neighbor processes for import:\n");
185 if (i % 10) fprintf(fp,
"\n");
187 fprintf(fp,
"number of neighbor processes for export: %d\n",
189 fprintf(fp,
"neighbor processes for export:\n");
193 if (i % 10) fprintf(fp,
"\n");
195 fprintf(fp,
"import index:\n");
197 fprintf(fp,
"%d%c", p->
import_index[i], (i + 1) % 10 ?
' ' :
'\n');
199 if (i % 10) fprintf(fp,
"\n");
201 fprintf(fp,
"import item:\n");
204 fprintf(fp,
"%d%c", p->
import_item[j], (j + 1) % 10 ?
' ' :
'\n');
207 if (j % 10) fprintf(fp,
"\n");
209 fprintf(fp,
"export index:\n");
211 fprintf(fp,
"%d%c", p->
export_index[i], (i + 1) % 10 ?
' ' :
'\n');
213 if (i % 10) fprintf(fp,
"\n");
215 fprintf(fp,
"export item:\n");
218 fprintf(fp,
"%d%c", p->
export_item[j], (j + 1) % 10 ?
' ' :
'\n');
221 if (j % 10) fprintf(fp,
"\n");
226 static int bcast_mapped_point_d2s_n(
232 int n_pe_send = 0, n_pe_recv = 0, *pe_send =
NULL, *pe_recv =
NULL;
233 int sendbuf_size = 0, *recvbuf_index =
NULL, *sendbuf =
NULL, *recvbuf =
NULL;
241 n_pe_send = comm_src->
psize;
245 if (pe_send ==
NULL) {
249 for (i = 0; i < n_pe_send; i++) {
250 pe_send[i] = comm_src->
ranks[i];
257 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_size + 1));
258 if (sendbuf ==
NULL) {
262 sendbuf[0] = mapped_point->
n;
270 n_pe_recv = comm_dst->
psize;
274 if (pe_recv ==
NULL) {
278 for (i = 0; i < n_pe_recv; i++) {
279 pe_recv[i] = comm_dst->
ranks[i];
283 recvbuf_index = (
int *)
HECMW_calloc(n_pe_recv + 1,
sizeof(
int));
284 if (recvbuf_index ==
NULL) {
288 for (i = 0; i < n_pe_recv; i++) {
289 recvbuf_index[i + 1] = recvbuf_index[i] + 1;
293 recvbuf = (
int *)
HECMW_calloc(recvbuf_index[n_pe_recv] + 1,
sizeof(
int));
294 if (recvbuf ==
NULL) {
304 pe_recv, recvbuf_index, recvbuf,
HECMW_INT,
306 if (rtc != 0)
goto error;
309 for (i = 0; i < comm_dst->
psize; i++) {
310 all_mapped_point[i]->
n = recvbuf[i];
330 static int bcast_mapped_point_d2s_coord(
336 int n_pe_send = 0, n_pe_recv = 0, *pe_send =
NULL, *pe_recv =
NULL;
337 int sendbuf_size = 0, *recvbuf_index =
NULL;
338 double *sendbuf =
NULL, *recvbuf =
NULL;
339 int node, size, rtc, i, j;
346 n_pe_send = comm_src->
psize;
350 if (pe_send ==
NULL) {
354 for (i = 0; i < n_pe_send; i++) {
355 pe_send[i] = comm_src->
ranks[i];
359 sendbuf_size = mapped_point->
n * 3;
362 sendbuf = (
double *)
HECMW_malloc(
sizeof(
double) * (sendbuf_size + 1));
363 if (sendbuf ==
NULL) {
367 for (i = 0; i < mapped_point->
n * 3; i++) {
368 sendbuf[i] = mapped_point->
coord[i];
377 n_pe_recv = comm_dst->
psize;
381 if (pe_recv ==
NULL) {
385 for (i = 0; i < n_pe_recv; i++) {
386 pe_recv[i] = comm_dst->
ranks[i];
390 recvbuf_index = (
int *)
HECMW_calloc(n_pe_recv + 1,
sizeof(
int));
391 if (recvbuf_index ==
NULL) {
395 for (i = 0; i < n_pe_recv; i++) {
396 recvbuf_index[i + 1] = recvbuf_index[i] + all_mapped_point[i]->
n * 3;
401 (
double *)
HECMW_malloc(
sizeof(
double) * (recvbuf_index[n_pe_recv] + 1));
402 if (recvbuf ==
NULL) {
412 if (rtc != 0)
goto error;
416 for (i = 0; i < comm_dst->
psize; i++) {
417 size = recvbuf_index[i + 1] - recvbuf_index[i];
419 if (size == 0)
continue;
421 all_mapped_point[i]->
coord =
423 if (all_mapped_point[i]->coord ==
NULL) {
428 for (j = recvbuf_index[i]; j < recvbuf_index[i + 1]; j++) {
429 all_mapped_point[i]->
coord[j - recvbuf_index[i]] = recvbuf[j];
451 static int bcast_mapped_point_d2s(
460 for (i = 0; i < comm_dst->
psize; i++) {
462 if (all_mapped_point[i] ==
NULL)
goto error;
466 if (bcast_mapped_point_d2s_n(mapped_point, comm_src, comm_dst, intercomm,
469 if (bcast_mapped_point_d2s_coord(mapped_point, comm_src, comm_dst, intercomm,
476 if (all_mapped_point) {
477 for (i = 0; i < comm_dst->
psize; i++) {
479 all_mapped_point[i] =
NULL;
492 int n_pe_send = 0, n_pe_recv = 0, *pe_send =
NULL, *pe_recv =
NULL;
493 int sendbuf_size = 0, *recvbuf_index =
NULL;
494 double *sendbuf =
NULL, *recvbuf =
NULL;
496 int N_BOUNDING_BOX_MEMBER = 6;
503 n_pe_send = comm_src->
psize;
507 if (pe_send ==
NULL) {
511 for (i = 0; i < n_pe_send; i++) {
512 pe_send[i] = comm_src->
ranks[i];
516 sendbuf_size = N_BOUNDING_BOX_MEMBER;
519 sendbuf = (
double *)
HECMW_malloc(
sizeof(
double) * (sendbuf_size + 1));
520 if (sendbuf ==
NULL) {
538 n_pe_recv = comm_dst->
psize;
542 if (pe_recv ==
NULL) {
546 for (i = 0; i < n_pe_recv; i++) {
547 pe_recv[i] = comm_dst->
ranks[i];
551 recvbuf_index = (
int *)
HECMW_calloc(n_pe_recv + 1,
sizeof(
int));
552 if (recvbuf_index ==
NULL) {
556 for (i = 0; i < n_pe_recv; i++) {
557 recvbuf_index[i + 1] = recvbuf_index[i] + N_BOUNDING_BOX_MEMBER;
562 (
double *)
HECMW_malloc(
sizeof(
double) * (recvbuf_index[n_pe_recv] + 1));
563 if (recvbuf ==
NULL) {
575 if (rtc != 0)
goto error;
581 for (i = 0; i < comm_dst->
psize; i++) {
583 N_BOUNDING_BOX_MEMBER);
585 all_dst_bbox[i].
min_x = recvbuf[recvbuf_index[i]];
586 all_dst_bbox[i].
min_y = recvbuf[recvbuf_index[i] + 1];
587 all_dst_bbox[i].
min_z = recvbuf[recvbuf_index[i] + 2];
588 all_dst_bbox[i].
max_x = recvbuf[recvbuf_index[i] + 3];
589 all_dst_bbox[i].
max_y = recvbuf[recvbuf_index[i] + 4];
590 all_dst_bbox[i].
max_z = recvbuf[recvbuf_index[i] + 5];
623 static int check_node_within_bbox(
626 double coord_x, coord_y, coord_z;
629 for (n = 0, i = 0; i < mapped_point->
n; i++) {
630 coord_x = mapped_point->
coord[3 * i];
631 coord_y = mapped_point->
coord[3 * i + 1];
632 coord_z = mapped_point->
coord[3 * i + 2];
634 if (coord_x >= box_src->
min_x && coord_x <= box_src->max_x &&
635 coord_y >= box_src->
min_y && coord_y <= box_src->max_y &&
636 coord_z >= box_src->
min_z && coord_z <= box_src->max_z) {
644 return (n != 0) ? 1 : 0;
647 static int set_candidate_node(
660 if (all_dst_bbox ==
NULL) {
664 for (i = 0; i < comm_dst->
psize; i++) {
665 all_dst_bbox[i].
min_x = 0.0;
666 all_dst_bbox[i].
min_y = 0.0;
667 all_dst_bbox[i].
min_z = 0.0;
668 all_dst_bbox[i].
max_x = 0.0;
669 all_dst_bbox[i].
max_y = 0.0;
670 all_dst_bbox[i].
max_z = 0.0;
675 if (bcast_bbox_d2s(bbox_dst, comm_src, comm_dst, intercomm, all_dst_bbox))
680 for (i = 0; i < comm_dst->
psize; i++) {
681 if (all_mapped_point[i]->n == 0)
continue;
684 (
int *)
HECMW_calloc(all_mapped_point[i]->n,
sizeof(
int));
685 if (is_candidate[i] ==
NULL) {
690 if (check_bbox_within_bbox(bbox_src->
enlarged, &all_dst_bbox[i])) {
691 check_node_within_bbox(bbox_src->
enlarged, all_mapped_point[i],
703 for (i = 0; i < comm_dst->
psize; i++) {
705 is_candidate[i] =
NULL;
720 double coord_x, coord_y, coord_z;
721 int bgcell, node, ic, i, j, l, m,
n;
725 if (map_to_bgcell ==
NULL) {
732 if (bgcell_src->
n == 0)
return map_to_bgcell;
737 if (bgcell_node_list ==
NULL) {
741 for (i = 0; i < bgcell_src->
n; i++) {
742 bgcell_node_list[i].
item = 0;
746 for (ic = 0, i = 0; i < boundary_src->
node->
n; i++) {
748 coord_x = mesh_src->
node[3 * (node - 1)];
749 coord_y = mesh_src->
node[3 * (node - 1) + 1];
750 coord_z = mesh_src->
node[3 * (node - 1) + 2];
759 if (l >= bgcell_src->
nx) l = bgcell_src->
nx - 1;
760 if (m >= bgcell_src->
ny) m = bgcell_src->
ny - 1;
761 if (
n >= bgcell_src->
nz)
n = bgcell_src->
nz - 1;
763 bgcell = bgcell_src->
nx * bgcell_src->
ny *
n + bgcell_src->
nx * m + l;
771 p->next = bgcell_node_list[bgcell].
next;
772 bgcell_node_list[bgcell].
next = p;
784 if (map_to_bgcell->
id ==
NULL) {
789 for (ic = 0, i = 0; i < bgcell_src->
n; i++) {
790 p = bgcell_node_list[i].
next;
792 map_to_bgcell->
id[ic++] = p->item;
795 map_to_bgcell->
index[i + 1] = ic;
799 for (i = 0; i < bgcell_src->
n; i++) {
800 free_link_list(bgcell_node_list[i].
next);
804 return map_to_bgcell;
807 for (i = 0; i < bgcell_src->
n; i++) {
808 free_link_list(bgcell_node_list[i].
next);
826 double coord_x, coord_y, coord_z, min_x, min_y, min_z, max_x, max_y, max_z;
827 int min_l, min_m, min_n, max_l, max_m, max_n;
828 int bgcell, elem, node, ic, i, l, m,
n;
833 if (map_to_bgcell ==
NULL) {
840 if (bgcell_src->
n == 0)
return map_to_bgcell;
845 if (bgcell_elem_list ==
NULL) {
849 for (i = 0; i < bgcell_src->
n; i++) {
850 bgcell_elem_list[i].
item = 0;
854 for (ic = 0, i = 0; i < boundary_src->
elem->
n; i++) {
859 j < mesh_src->elem_node_index[elem]; j++) {
861 coord_x = mesh_src->
node[3 * (node - 1)];
862 coord_y = mesh_src->
node[3 * (node - 1) + 1];
863 coord_z = mesh_src->
node[3 * (node - 1) + 2];
864 if (coord_x < min_x) min_x = coord_x;
865 if (coord_y < min_y) min_y = coord_y;
866 if (coord_z < min_z) min_z = coord_z;
867 if (coord_x > max_x) max_x = coord_x;
868 if (coord_y > max_y) max_y = coord_y;
869 if (coord_z > max_z) max_z = coord_z;
885 if (min_l < 0) min_l = 0;
886 if (min_m < 0) min_m = 0;
887 if (min_n < 0) min_n = 0;
888 if (max_l < 0) max_l = 0;
889 if (max_m < 0) max_m = 0;
890 if (max_n < 0) max_n = 0;
891 if (min_l >= bgcell_src->
nx) min_l = bgcell_src->
nx - 1;
892 if (min_m >= bgcell_src->
ny) min_m = bgcell_src->
ny - 1;
893 if (min_n >= bgcell_src->
nz) min_n = bgcell_src->
nz - 1;
894 if (max_l >= bgcell_src->
nx) max_l = bgcell_src->
nx - 1;
895 if (max_m >= bgcell_src->
ny) max_m = bgcell_src->
ny - 1;
896 if (max_n >= bgcell_src->
nz) max_n = bgcell_src->
nz - 1;
898 for (l = min_l; l <= max_l; l++) {
899 for (m = min_m; m <= max_m; m++) {
900 for (
n = min_n;
n <= max_n;
n++) {
901 bgcell = bgcell_src->
nx * bgcell_src->
ny *
n + bgcell_src->
nx * m + l;
909 p->next = bgcell_elem_list[bgcell].
next;
910 bgcell_elem_list[bgcell].
next = p;
925 if (map_to_bgcell->
id ==
NULL) {
930 for (ic = 0, i = 0; i < bgcell_src->
n; i++) {
931 p = bgcell_elem_list[i].
next;
933 map_to_bgcell->
id[ic++] = p->item;
936 map_to_bgcell->
index[i + 1] = ic;
940 for (i = 0; i < bgcell_src->
n; i++) {
941 free_link_list(bgcell_elem_list[i].
next);
945 return map_to_bgcell;
948 for (i = 0; i < bgcell_src->
n; i++) {
949 free_link_list(bgcell_elem_list[i].
next);
966 double coord_x, coord_y, coord_z, min_x, min_y, min_z, max_x, max_y, max_z;
967 int min_l, min_m, min_n, max_l, max_m, max_n;
968 int bgcell, elem, node, ic, i, l, m,
n;
974 if (map_to_bgcell ==
NULL) {
981 if (bgcell_src->
n == 0)
return map_to_bgcell;
986 if (bgcell_surf_list ==
NULL) {
990 for (i = 0; i < bgcell_src->
n; i++) {
991 bgcell_surf_list[i].
item = 0;
995 for (ic = 0, i = 0; i < boundary_src->
surf->
n; i++) {
996 elem = boundary_src->
surf->
item[2 * i];
1000 j < mesh_src->elem_node_index[elem]; j++) {
1002 coord_x = mesh_src->
node[3 * (node - 1)];
1003 coord_y = mesh_src->
node[3 * (node - 1) + 1];
1004 coord_z = mesh_src->
node[3 * (node - 1) + 2];
1005 if (coord_x < min_x) min_x = coord_x;
1006 if (coord_y < min_y) min_y = coord_y;
1007 if (coord_z < min_z) min_z = coord_z;
1008 if (coord_x > max_x) max_x = coord_x;
1009 if (coord_y > max_y) max_y = coord_y;
1010 if (coord_z > max_z) max_z = coord_z;
1026 if (min_l < 0) min_l = 0;
1027 if (min_m < 0) min_m = 0;
1028 if (min_n < 0) min_n = 0;
1029 if (max_l < 0) max_l = 0;
1030 if (max_m < 0) max_m = 0;
1031 if (max_n < 0) max_n = 0;
1032 if (min_l >= bgcell_src->
nx) min_l = bgcell_src->
nx - 1;
1033 if (min_m >= bgcell_src->
ny) min_m = bgcell_src->
ny - 1;
1034 if (min_n >= bgcell_src->
nz) min_n = bgcell_src->
nz - 1;
1035 if (max_l >= bgcell_src->
nx) max_l = bgcell_src->
nx - 1;
1036 if (max_m >= bgcell_src->
ny) max_m = bgcell_src->
ny - 1;
1037 if (max_n >= bgcell_src->
nz) max_n = bgcell_src->
nz - 1;
1039 for (l = min_l; l <= max_l; l++) {
1040 for (m = min_m; m <= max_m; m++) {
1041 for (
n = min_n;
n <= max_n;
n++) {
1042 bgcell = bgcell_src->
nx * bgcell_src->
ny *
n + bgcell_src->
nx * m + l;
1049 p->next = bgcell_surf_list[bgcell].
next;
1050 bgcell_surf_list[bgcell].
next = p;
1065 if (map_to_bgcell->
id ==
NULL) {
1070 for (ic = 0, i = 0; i < bgcell_src->
n; i++) {
1071 for (p = bgcell_surf_list[i].
next; p; p = p->
next) {
1072 map_to_bgcell->
id[ic++] = p->item;
1074 map_to_bgcell->
index[i + 1] = ic;
1078 for (i = 0; i < bgcell_src->
n; i++) {
1079 free_link_list(bgcell_surf_list[i].
next);
1083 return map_to_bgcell;
1086 for (i = 0; i < bgcell_src->
n; i++) {
1087 free_link_list(bgcell_surf_list[i].
next);
1090 if (map_to_bgcell) {
1099 static int compare_mapping_info(
int n_positive_old,
double dot_product_old,
1100 double distance_old,
int n_positive_new,
1101 double dot_product_new,
double distance_new) {
1105 if (n_positive_old < 0)
return 1;
1106 if (n_positive_new < n_positive_old)
return 1;
1107 if (n_positive_new > n_positive_old)
return 0;
1114 if (dot_product_old > 0 && dot_product_new < 0)
return 0;
1116 if (dot_product_old < 0 && dot_product_new > 0)
return 1;
1122 if (distance_new < distance_old)
return 1;
1127 static int map_point_to_surf(
1134 double coord_x, coord_y, coord_z;
1135 int depth_x_before, depth_y_before, depth_z_before, depth_x_after,
1136 depth_y_after, depth_z_after;
1137 double dot_product, distance;
1138 int n_positive, elem, surf, bgcell, surf_id, nl, nm, nn, rtc, jstart, jfinal,
1141 map_src->
n = mapped_point->
n;
1142 if (map_src->
n == 0)
return 0;
1145 if (map_src->
id ==
NULL) {
1164 for (i = 0; i < map_src->
n; i++) {
1165 map_src->
id[i] = -1;
1171 for (i = 0; i < mapped_point->
n; i++) {
1172 if (is_candidate[i] == 0)
continue;
1174 coord_x = mapped_point->
coord[3 * i];
1175 coord_y = mapped_point->
coord[3 * i + 1];
1176 coord_z = mapped_point->
coord[3 * i + 2];
1185 if (nl >= bgcell_src->
nx) nl = bgcell_src->
nx - 1;
1186 if (nm >= bgcell_src->
ny) nm = bgcell_src->
ny - 1;
1187 if (nn >= bgcell_src->
nz) nn = bgcell_src->
nz - 1;
1189 bgcell = bgcell_src->
nx * bgcell_src->
ny * nn + bgcell_src->
nx * nm + nl;
1192 for (j = map_to_bgcell->
index[bgcell]; j < map_to_bgcell->index[bgcell + 1];
1194 surf_id = map_to_bgcell->
id[j];
1195 elem = boundary_src->
surf->
item[2 * surf_id];
1196 surf = boundary_src->
surf->
item[2 * surf_id + 1];
1201 coord_z, &dot_product, &distance);
1205 coord_z, &dot_product, &distance);
1211 if (n_positive >= 0) {
1212 rtc = compare_mapping_info(
1214 map_src->
distance[i], n_positive, dot_product, distance);
1219 map_src->
id[i] = surf_id;
1234 int **is_candidate,
struct map_info **map_src) {
1241 if (map_to_bgcell ==
NULL) {
1246 map_to_bgcell->
id =
NULL;
1254 map_surf_to_bgcell(mesh_src, boundary_src, bbox_src, bgcell_src);
1255 if (map_to_bgcell ==
NULL)
goto error;
1257 for (i = 0; i < comm_dst->
psize; i++) {
1258 if (map_point_to_surf(mesh_src, boundary_src, bbox_src, bgcell_src,
1259 all_mapped_point[i], is_candidate[i], map_to_bgcell,
1269 if (map_to_bgcell) {
1277 if (map_to_bgcell) {
1283 for (i = 0; i < comm_dst->
psize; i++) {
1284 free_struct_map_info(map_src[i]);
1293 static int gather_id_s2d(
struct map_info **map_src,
1298 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1299 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
1308 n_send_pe = comm_dst->
psize;
1311 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1312 if (send_pe ==
NULL) {
1316 for (i = 0; i < n_send_pe; i++) {
1317 send_pe[i] = comm_dst->
ranks[i];
1321 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1322 if (sendbuf_index ==
NULL) {
1326 for (i = 0; i < n_send_pe; i++) {
1327 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1331 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_index[n_send_pe] + 1));
1332 if (sendbuf ==
NULL) {
1336 for (i = 0; i < comm_dst->
psize; i++) {
1337 for (j = 0; j < map_src[i]->
n; j++) {
1338 sendbuf[sendbuf_index[i] + j] = map_src[i]->
id[j];
1348 n_recv_pe = comm_src->
psize;
1351 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1352 if (recv_pe ==
NULL) {
1356 for (i = 0; i < n_recv_pe; i++) {
1357 recv_pe[i] = comm_src->
ranks[i];
1361 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1362 if (recvbuf_index ==
NULL) {
1366 for (i = 0; i < n_recv_pe; i++) {
1367 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1371 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (recvbuf_index[n_recv_pe] + 1));
1372 if (recvbuf ==
NULL) {
1382 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1384 if (rtc != 0)
goto error;
1390 for (i = 0; i < n_recv_pe; i++) {
1391 map_dst[i]->
id = (
int *)
HECMW_calloc(map_dst[i]->n,
sizeof(
int));
1392 if (map_dst[i]->
id ==
NULL) {
1396 for (j = 0; j < map_dst[i]->
n; j++) {
1397 map_dst[i]->
id[j] = recvbuf[recvbuf_index[i] + j];
1420 static int gather_n_positive_s2d(
struct map_info **map_src,
1425 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1426 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
1435 n_send_pe = comm_dst->
psize;
1438 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1439 if (send_pe ==
NULL) {
1443 for (i = 0; i < n_send_pe; i++) {
1444 send_pe[i] = comm_dst->
ranks[i];
1448 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1449 if (sendbuf_index ==
NULL) {
1453 for (i = 0; i < n_send_pe; i++) {
1454 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1458 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_index[n_send_pe] + 1));
1459 if (sendbuf ==
NULL) {
1463 for (i = 0; i < comm_dst->
psize; i++) {
1464 for (j = 0; j < map_src[i]->
n; j++) {
1465 sendbuf[sendbuf_index[i] + j] = map_src[i]->
n_positive[j];
1475 n_recv_pe = comm_src->
psize;
1478 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1479 if (recv_pe ==
NULL) {
1483 for (i = 0; i < n_recv_pe; i++) {
1484 recv_pe[i] = comm_src->
ranks[i];
1488 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1489 if (recvbuf_index ==
NULL) {
1493 for (i = 0; i < n_recv_pe; i++) {
1494 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1498 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (recvbuf_index[n_recv_pe] + 1));
1499 if (recvbuf ==
NULL) {
1509 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1511 if (rtc != 0)
goto error;
1517 for (i = 0; i < n_recv_pe; i++) {
1519 if (map_dst[i]->n_positive ==
NULL) {
1523 for (j = 0; j < map_dst[i]->
n; j++) {
1524 map_dst[i]->
n_positive[j] = recvbuf[recvbuf_index[i] + j];
1547 static int gather_dot_product_s2d(
struct map_info **map_src,
1552 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1553 int *sendbuf_index =
NULL, *recvbuf_index =
NULL;
1554 double *sendbuf =
NULL, *recvbuf =
NULL;
1562 n_send_pe = comm_dst->
psize;
1565 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1566 if (send_pe ==
NULL) {
1570 for (i = 0; i < n_send_pe; i++) {
1571 send_pe[i] = comm_dst->
ranks[i];
1575 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1576 if (sendbuf_index ==
NULL) {
1580 for (i = 0; i < n_send_pe; i++) {
1581 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1586 (
double *)
HECMW_malloc(
sizeof(
double) * (sendbuf_index[n_send_pe] + 1));
1587 if (sendbuf ==
NULL) {
1591 for (i = 0; i < comm_dst->
psize; i++) {
1592 for (j = 0; j < map_src[i]->
n; j++) {
1593 sendbuf[sendbuf_index[i] + j] = map_src[i]->
dot_product[j];
1603 n_recv_pe = comm_src->
psize;
1606 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1607 if (recv_pe ==
NULL) {
1611 for (i = 0; i < n_recv_pe; i++) {
1612 recv_pe[i] = comm_src->
ranks[i];
1616 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1617 if (recvbuf_index ==
NULL) {
1621 for (i = 0; i < n_recv_pe; i++) {
1622 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1627 (
double *)
HECMW_malloc(
sizeof(
double) * recvbuf_index[n_recv_pe] + 1);
1628 if (recvbuf ==
NULL) {
1638 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1640 if (rtc != 0)
goto error;
1646 for (i = 0; i < n_recv_pe; i++) {
1649 if (map_dst[i]->dot_product ==
NULL) {
1653 for (j = 0; j < map_dst[i]->
n; j++) {
1654 map_dst[i]->
dot_product[j] = recvbuf[recvbuf_index[i] + j];
1677 static int gather_distance_s2d(
struct map_info **map_src,
1682 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1683 int *sendbuf_index =
NULL, *recvbuf_index =
NULL;
1684 double *sendbuf =
NULL, *recvbuf =
NULL;
1692 n_send_pe = comm_dst->
psize;
1695 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1696 if (send_pe ==
NULL) {
1700 for (i = 0; i < n_send_pe; i++) {
1701 send_pe[i] = comm_dst->
ranks[i];
1705 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1706 if (sendbuf_index ==
NULL) {
1710 for (i = 0; i < n_send_pe; i++) {
1711 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1716 (
double *)
HECMW_malloc(
sizeof(
double) * (sendbuf_index[n_send_pe] + 1));
1717 if (sendbuf ==
NULL) {
1721 for (i = 0; i < comm_dst->
psize; i++) {
1722 for (j = 0; j < map_src[i]->
n; j++) {
1723 sendbuf[sendbuf_index[i] + j] = map_src[i]->
distance[j];
1731 n_recv_pe = comm_src->
psize;
1734 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1735 if (recv_pe ==
NULL) {
1739 for (i = 0; i < n_recv_pe; i++) {
1740 recv_pe[i] = comm_src->
ranks[i];
1744 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1745 if (recvbuf_index ==
NULL) {
1749 for (i = 0; i < n_recv_pe; i++) {
1750 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1755 (
double *)
HECMW_malloc(
sizeof(
double) * (recvbuf_index[n_recv_pe] + 1));
1756 if (recvbuf ==
NULL) {
1766 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1768 if (rtc != 0)
goto error;
1774 for (i = 0; i < n_recv_pe; i++) {
1777 if (map_dst[i]->distance ==
NULL) {
1781 for (j = 0; j < map_dst[i]->
n; j++) {
1782 map_dst[i]->
distance[j] = recvbuf[recvbuf_index[i] + j];
1807 static int gather_map_data_s2d(
1812 int map_type, rtc, i;
1815 for (i = 0; i < comm_src->
psize; i++) {
1816 map_dst[i] = alloc_struct_map_info();
1817 if (map_dst[i] ==
NULL)
goto error;
1819 map_dst[i]->
n = mapped_point->
n;
1827 if (gather_id_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1829 if (gather_n_positive_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1831 if (gather_dot_product_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1833 if (gather_distance_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1845 for (i = 0; i < comm_src->
psize; i++) {
1846 free_struct_map_info(map_dst[i]);
1859 double _dot_product, _distance;
1860 int _n_positive, _item, pe_index, index, size, rtc, n, i, j;
1864 if (mapping_data_list ==
NULL) {
1868 for (i = 0; i < comm_src->
psize; i++) {
1870 mapping_data_list[i].
id = -1;
1871 mapping_data_list[i].
item = -1;
1874 for (n = 0, i = 0; i < mapped_point->
n; i++) {
1877 for (j = 0; j < comm_src->
psize; j++) {
1878 if (map_dst[j]->n_positive[i] >= 0) {
1879 rtc = compare_mapping_info(
1880 _n_positive, _dot_product, _distance, map_dst[j]->n_positive[i],
1881 map_dst[j]->dot_product[i], map_dst[j]->distance[i]);
1884 _item = map_dst[j]->
id[i];
1887 _distance = map_dst[j]->
distance[i];
1892 if (_n_positive >= 0) {
1898 p->next = mapping_data_list[pe_index].
next;
1899 p->
id = mapped_point->
id[n++];
1901 mapping_data_list[pe_index].
next = p;
1905 return mapping_data_list;
1908 if (mapping_data_list) {
1909 for (i = 0; i < comm_src->
psize; i++) {
1910 free_link_list_map(mapping_data_list[i].
next);
1920 static int set_n_neighbor_pe_import(
1926 for (n = 0, i = 0; i < comm_src->
psize; i++) {
1927 if (mapping_data_list[i].
next) n++;
1947 for (n = 0, i = 0; i < comm_src->
psize; i++) {
1948 if (mapping_data_list[i].
next) {
1970 for (m = 0, n = 0, i = 0; i < comm_src->
psize; i++) {
1971 if (mapping_data_list[i].
next) {
1972 for (p = mapping_data_list[i].
next; p; p = p->
next) {
1996 for (n = 0, i = 0; i < comm_src->
psize; i++) {
1997 if (mapping_data_list[i].
next) {
1998 for (p = mapping_data_list[i].
next; p; p = p->
next) {
2014 int *export_data =
NULL;
2019 if (export_data ==
NULL) {
2024 for (n = 0, i = 0; i < comm_src->
psize; i++) {
2025 if (mapping_data_list[i].
next) {
2026 for (p = mapping_data_list[i].
next; p; p = p->
next) {
2027 export_data[n++] = p->
item;
2036 static int set_neighbor_info_import(
2043 if (set_n_neighbor_pe_import(inter_tbl, comm_src, mapping_data_list))
2047 if (set_neighbor_pe_import(inter_tbl, comm_src, mapping_data_list))
return -1;
2050 if (set_import_index(inter_tbl, comm_src, mapping_data_list))
return -1;
2053 if (set_import_item(inter_tbl, comm_src, mapping_data_list))
return -1;
2060 static int set_neighbor_pe_export(
2066 int n_send_pe = 0, n_recv_pe = 0;
2067 int *send_pe =
NULL, *recv_pe =
NULL;
2068 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
2070 int size, rtc, n, i;
2077 n_send_pe = comm_src->
psize;
2080 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
2081 if (send_pe ==
NULL) {
2085 for (i = 0; i < comm_src->
psize; i++) {
2086 send_pe[i] = comm_src->
ranks[i];
2090 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
2091 if (sendbuf_index ==
NULL) {
2095 for (i = 0; i < n_send_pe; i++) {
2096 sendbuf_index[i + 1] = sendbuf_index[i] + 1;
2100 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_index[n_send_pe] + 1));
2101 if (sendbuf ==
NULL) {
2105 for (i = 0; i < n_send_pe; i++) {
2106 if (mapping_data_list[i].
next) {
2119 n_recv_pe = comm_dst->
psize;
2122 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
2123 if (recv_pe ==
NULL) {
2127 for (i = 0; i < comm_dst->
psize; i++) {
2128 recv_pe[i] = comm_dst->
ranks[i];
2132 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
2133 if (recvbuf_index ==
NULL) {
2137 for (i = 0; i < n_recv_pe; i++) {
2138 recvbuf_index[i + 1] = recvbuf_index[i] + 1;
2142 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (recvbuf_index[n_recv_pe] + 1));
2143 if (recvbuf ==
NULL) {
2151 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
2153 if (rtc != 0)
goto error;
2159 for (n = 0, i = 0; i < comm_dst->
psize; i++) {
2160 if (recvbuf[i] > 0) n++;
2171 for (n = 0, i = 0; i < comm_dst->
psize; i++) {
2172 if (recvbuf[i] > 0) {
2202 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
2213 if (sendbuf_index ==
NULL) {
2218 sendbuf_index[i + 1] = sendbuf_index[i] + 1;
2224 if (sendbuf ==
NULL) {
2240 if (recvbuf_index ==
NULL) {
2245 recvbuf_index[i + 1] = recvbuf_index[i] + 1;
2251 if (recvbuf ==
NULL) {
2269 if (rtc != 0)
goto error;
2320 size =
sizeof(int) *
2337 if (rtc != 0)
goto error;
2352 int *export_data =
NULL;
2357 if (inter_tbl ==
NULL)
goto error;
2361 mapping_data_list = set_mapping_surf(mapped_point, comm_src, map_dst);
2362 if (mapping_data_list ==
NULL)
goto error;
2364 rtc = set_neighbor_info_import(inter_tbl, mapping_data_list, comm_src);
2367 export_data = set_export_data(inter_tbl, comm_src, mapping_data_list);
2368 if (export_data ==
NULL)
goto error;
2372 rtc = set_neighbor_pe_export(inter_tbl, comm_src, comm_dst, intercomm,
2376 rtc = set_export_index(inter_tbl, comm_src, comm_dst, intercomm);
2379 rtc = set_export_item(inter_tbl, comm_src, comm_dst, intercomm, export_data);
2407 int **is_candidate =
NULL;
2413 if (all_mapped_point ==
NULL) {
2417 for (i = 0; i < comm_dst->
psize; i++) {
2418 all_mapped_point[i] =
NULL;
2422 if (is_candidate ==
NULL) {
2426 for (i = 0; i < comm_dst->
psize; i++) {
2427 is_candidate[i] =
NULL;
2431 rtc = bcast_mapped_point_d2s(mapped_point, comm_src, comm_dst, intercomm,
2435 rtc = set_candidate_node(bbox_src, bbox_dst, comm_src, comm_dst, intercomm,
2436 all_mapped_point, is_candidate);
2443 if (map_src ==
NULL) {
2447 for (i = 0; i < comm_dst->
psize; i++) {
2450 for (i = 0; i < comm_dst->
psize; i++) {
2451 map_src[i] = alloc_struct_map_info();
2452 if (map_src[i] ==
NULL)
goto error;
2458 rtc = mapping_in_src(mesh_src, boundary_src, bbox_src, bgcell_src, comm_dst,
2459 all_mapped_point, is_candidate, map_src);
2463 if (all_mapped_point) {
2464 for (i = 0; i < comm_dst->
psize; i++) {
2470 for (i = 0; i < comm_dst->
psize; i++) {
2480 if (map_dst ==
NULL) {
2484 for (i = 0; i < comm_src->
psize; i++) {
2489 rtc = gather_map_data_s2d(mapped_point, map_src, comm_src, comm_dst,
2490 intercomm, map_dst);
2495 set_inter_iftable(comm_src, comm_dst, intercomm, map_dst, mapped_point);
2496 if (inter_tbl ==
NULL)
goto error;
2501 if (all_mapped_point) {
2502 for (i = 0; i < comm_dst->
psize; i++) {
2508 for (i = 0; i < comm_dst->
psize; i++) {
int HECMW_couple_bcast(int n_neighbor_pe_send, int *neighbor_pe_send, int sendbuf_size, void *sendbuf, int n_neighbor_pe_recv, int *neighbor_pe_recv, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
int HECMW_couple_inter_send_recv(int n_neighbor_pe_send, int *neighbor_pe_send, int *sendbuf_index, void *sendbuf, int n_neighbor_pe_recv, int *neighbor_pe_recv, int *recvbuf_index, void *recvbuf, HECMW_Datatype datatype, HECMW_Comm comm)
#define HECMWCPL_E_INVALID_MAPTYPE
#define HECMW_COUPLE_MAP_SURF_TO_SURF
#define HECMWCPL_E_NONSUPPORT_ETYPE
#define HECMW_COUPLE_MAP_NODE_TO_SURF
void HECMW_couple_free_inter_iftable(struct hecmw_couple_inter_iftable *p)
struct hecmw_couple_inter_iftable * HECMW_couple_alloc_inter_iftable(void)
struct hecmw_couple_inter_iftable * HECMW_couple_set_map_data(const struct hecmwST_local_mesh *mesh_src, const struct hecmwST_local_mesh *mesh_dst, const struct hecmw_couple_comm *comm_src, const struct hecmw_couple_comm *comm_dst, const struct hecmw_couple_comm *intercomm, const struct hecmw_couple_boundary *boundary_src, const struct hecmw_couple_bounding_box *bbox_src, const struct hecmw_couple_bounding_box *bbox_dst, const struct hecmw_couple_background_cell *bgcell_src, const struct hecmw_couple_mapped_point *mapped_point)
void HECMW_couple_print_inter_iftable(const struct hecmw_couple_inter_iftable *p, FILE *fp)
int HECMW_couple_judge_hex1(const struct hecmwST_local_mesh *local_mesh, int elem, int surf_id, double coord_px, double coord_py, double coord_pz, double *dot_product, double *distance)
int HECMW_couple_judge_tet1(const struct hecmwST_local_mesh *local_mesh, int elem, int surf_id, double coord_px, double coord_py, double coord_pz, double *dot_product, double *distance)
struct hecmw_couple_mapped_point * HECMW_couple_alloc_mapped_point(void)
void HECMW_couple_free_mapped_point(struct hecmw_couple_mapped_point *p)
int HECMW_set_error(int errorno, const char *fmt,...)
#define HECMW_calloc(nmemb, size)
#define HECMW_malloc(size)
#define HECMW_assert(cond)
struct hecmw_couple_boundary_item * elem
struct hecmw_couple_boundary_item * node
struct hecmw_couple_boundary_item * surf
struct hecmw_couple_box * enlarged
long long * elem_node_index
struct link_list_map * next