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, j, l, m,
n;
832 if (map_to_bgcell ==
NULL) {
839 if (bgcell_src->
n == 0)
return map_to_bgcell;
844 if (bgcell_elem_list ==
NULL) {
848 for (i = 0; i < bgcell_src->
n; i++) {
849 bgcell_elem_list[i].
item = 0;
853 for (ic = 0, i = 0; i < boundary_src->
elem->
n; i++) {
858 j < mesh_src->elem_node_index[elem]; j++) {
860 coord_x = mesh_src->
node[3 * (node - 1)];
861 coord_y = mesh_src->
node[3 * (node - 1) + 1];
862 coord_z = mesh_src->
node[3 * (node - 1) + 2];
863 if (coord_x < min_x) min_x = coord_x;
864 if (coord_y < min_y) min_y = coord_y;
865 if (coord_z < min_z) min_z = coord_z;
866 if (coord_x > max_x) max_x = coord_x;
867 if (coord_y > max_y) max_y = coord_y;
868 if (coord_z > max_z) max_z = coord_z;
884 if (min_l < 0) min_l = 0;
885 if (min_m < 0) min_m = 0;
886 if (min_n < 0) min_n = 0;
887 if (max_l < 0) max_l = 0;
888 if (max_m < 0) max_m = 0;
889 if (max_n < 0) max_n = 0;
890 if (min_l >= bgcell_src->
nx) min_l = bgcell_src->
nx - 1;
891 if (min_m >= bgcell_src->
ny) min_m = bgcell_src->
ny - 1;
892 if (min_n >= bgcell_src->
nz) min_n = bgcell_src->
nz - 1;
893 if (max_l >= bgcell_src->
nx) max_l = bgcell_src->
nx - 1;
894 if (max_m >= bgcell_src->
ny) max_m = bgcell_src->
ny - 1;
895 if (max_n >= bgcell_src->
nz) max_n = bgcell_src->
nz - 1;
897 for (l = min_l; l <= max_l; l++) {
898 for (m = min_m; m <= max_m; m++) {
899 for (
n = min_n;
n <= max_n;
n++) {
900 bgcell = bgcell_src->
nx * bgcell_src->
ny *
n + bgcell_src->
nx * m + l;
908 p->next = bgcell_elem_list[bgcell].
next;
909 bgcell_elem_list[bgcell].
next = p;
924 if (map_to_bgcell->
id ==
NULL) {
929 for (ic = 0, i = 0; i < bgcell_src->
n; i++) {
930 p = bgcell_elem_list[i].
next;
932 map_to_bgcell->
id[ic++] = p->item;
935 map_to_bgcell->
index[i + 1] = ic;
939 for (i = 0; i < bgcell_src->
n; i++) {
940 free_link_list(bgcell_elem_list[i].
next);
944 return map_to_bgcell;
947 for (i = 0; i < bgcell_src->
n; i++) {
948 free_link_list(bgcell_elem_list[i].
next);
965 double coord_x, coord_y, coord_z, min_x, min_y, min_z, max_x, max_y, max_z;
966 int min_l, min_m, min_n, max_l, max_m, max_n;
967 int bgcell, elem, node, ic, i, j, l, m,
n;
972 if (map_to_bgcell ==
NULL) {
979 if (bgcell_src->
n == 0)
return map_to_bgcell;
984 if (bgcell_surf_list ==
NULL) {
988 for (i = 0; i < bgcell_src->
n; i++) {
989 bgcell_surf_list[i].
item = 0;
993 for (ic = 0, i = 0; i < boundary_src->
surf->
n; i++) {
994 elem = boundary_src->
surf->
item[2 * i];
998 j < mesh_src->elem_node_index[elem]; j++) {
1000 coord_x = mesh_src->
node[3 * (node - 1)];
1001 coord_y = mesh_src->
node[3 * (node - 1) + 1];
1002 coord_z = mesh_src->
node[3 * (node - 1) + 2];
1003 if (coord_x < min_x) min_x = coord_x;
1004 if (coord_y < min_y) min_y = coord_y;
1005 if (coord_z < min_z) min_z = coord_z;
1006 if (coord_x > max_x) max_x = coord_x;
1007 if (coord_y > max_y) max_y = coord_y;
1008 if (coord_z > max_z) max_z = coord_z;
1024 if (min_l < 0) min_l = 0;
1025 if (min_m < 0) min_m = 0;
1026 if (min_n < 0) min_n = 0;
1027 if (max_l < 0) max_l = 0;
1028 if (max_m < 0) max_m = 0;
1029 if (max_n < 0) max_n = 0;
1030 if (min_l >= bgcell_src->
nx) min_l = bgcell_src->
nx - 1;
1031 if (min_m >= bgcell_src->
ny) min_m = bgcell_src->
ny - 1;
1032 if (min_n >= bgcell_src->
nz) min_n = bgcell_src->
nz - 1;
1033 if (max_l >= bgcell_src->
nx) max_l = bgcell_src->
nx - 1;
1034 if (max_m >= bgcell_src->
ny) max_m = bgcell_src->
ny - 1;
1035 if (max_n >= bgcell_src->
nz) max_n = bgcell_src->
nz - 1;
1037 for (l = min_l; l <= max_l; l++) {
1038 for (m = min_m; m <= max_m; m++) {
1039 for (
n = min_n;
n <= max_n;
n++) {
1040 bgcell = bgcell_src->
nx * bgcell_src->
ny *
n + bgcell_src->
nx * m + l;
1047 p->next = bgcell_surf_list[bgcell].
next;
1048 bgcell_surf_list[bgcell].
next = p;
1063 if (map_to_bgcell->
id ==
NULL) {
1068 for (ic = 0, i = 0; i < bgcell_src->
n; i++) {
1069 for (p = bgcell_surf_list[i].
next; p; p = p->
next) {
1070 map_to_bgcell->
id[ic++] = p->item;
1072 map_to_bgcell->
index[i + 1] = ic;
1076 for (i = 0; i < bgcell_src->
n; i++) {
1077 free_link_list(bgcell_surf_list[i].
next);
1081 return map_to_bgcell;
1084 for (i = 0; i < bgcell_src->
n; i++) {
1085 free_link_list(bgcell_surf_list[i].
next);
1088 if (map_to_bgcell) {
1097 static int compare_mapping_info(
int n_positive_old,
double dot_product_old,
1098 double distance_old,
int n_positive_new,
1099 double dot_product_new,
double distance_new) {
1103 if (n_positive_old < 0)
return 1;
1104 if (n_positive_new < n_positive_old)
return 1;
1105 if (n_positive_new > n_positive_old)
return 0;
1112 if (dot_product_old > 0 && dot_product_new < 0)
return 0;
1114 if (dot_product_old < 0 && dot_product_new > 0)
return 1;
1120 if (distance_new < distance_old)
return 1;
1125 static int map_point_to_surf(
1132 double coord_x, coord_y, coord_z;
1133 int depth_x_before, depth_y_before, depth_z_before, depth_x_after,
1134 depth_y_after, depth_z_after;
1135 double dot_product, distance;
1136 int n_positive, elem, surf, bgcell, surf_id, nl, nm, nn, rtc, jstart, jfinal,
1139 map_src->
n = mapped_point->
n;
1140 if (map_src->
n == 0)
return 0;
1143 if (map_src->
id ==
NULL) {
1162 for (i = 0; i < map_src->
n; i++) {
1163 map_src->
id[i] = -1;
1169 for (i = 0; i < mapped_point->
n; i++) {
1170 if (is_candidate[i] == 0)
continue;
1172 coord_x = mapped_point->
coord[3 * i];
1173 coord_y = mapped_point->
coord[3 * i + 1];
1174 coord_z = mapped_point->
coord[3 * i + 2];
1183 if (nl >= bgcell_src->
nx) nl = bgcell_src->
nx - 1;
1184 if (nm >= bgcell_src->
ny) nm = bgcell_src->
ny - 1;
1185 if (nn >= bgcell_src->
nz) nn = bgcell_src->
nz - 1;
1187 bgcell = bgcell_src->
nx * bgcell_src->
ny * nn + bgcell_src->
nx * nm + nl;
1190 for (j = map_to_bgcell->
index[bgcell]; j < map_to_bgcell->index[bgcell + 1];
1192 surf_id = map_to_bgcell->
id[j];
1193 elem = boundary_src->
surf->
item[2 * surf_id];
1194 surf = boundary_src->
surf->
item[2 * surf_id + 1];
1199 coord_z, &dot_product, &distance);
1203 coord_z, &dot_product, &distance);
1209 if (n_positive >= 0) {
1210 rtc = compare_mapping_info(
1212 map_src->
distance[i], n_positive, dot_product, distance);
1217 map_src->
id[i] = surf_id;
1232 int **is_candidate,
struct map_info **map_src) {
1239 if (map_to_bgcell ==
NULL) {
1244 map_to_bgcell->
id =
NULL;
1252 map_surf_to_bgcell(mesh_src, boundary_src, bbox_src, bgcell_src);
1253 if (map_to_bgcell ==
NULL)
goto error;
1255 for (i = 0; i < comm_dst->
psize; i++) {
1256 if (map_point_to_surf(mesh_src, boundary_src, bbox_src, bgcell_src,
1257 all_mapped_point[i], is_candidate[i], map_to_bgcell,
1267 if (map_to_bgcell) {
1275 if (map_to_bgcell) {
1281 for (i = 0; i < comm_dst->
psize; i++) {
1282 free_struct_map_info(map_src[i]);
1291 static int gather_id_s2d(
struct map_info **map_src,
1296 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1297 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
1306 n_send_pe = comm_dst->
psize;
1309 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1310 if (send_pe ==
NULL) {
1314 for (i = 0; i < n_send_pe; i++) {
1315 send_pe[i] = comm_dst->
ranks[i];
1319 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1320 if (sendbuf_index ==
NULL) {
1324 for (i = 0; i < n_send_pe; i++) {
1325 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1329 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_index[n_send_pe] + 1));
1330 if (sendbuf ==
NULL) {
1334 for (i = 0; i < comm_dst->
psize; i++) {
1335 for (j = 0; j < map_src[i]->
n; j++) {
1336 sendbuf[sendbuf_index[i] + j] = map_src[i]->
id[j];
1346 n_recv_pe = comm_src->
psize;
1349 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1350 if (recv_pe ==
NULL) {
1354 for (i = 0; i < n_recv_pe; i++) {
1355 recv_pe[i] = comm_src->
ranks[i];
1359 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1360 if (recvbuf_index ==
NULL) {
1364 for (i = 0; i < n_recv_pe; i++) {
1365 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1369 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (recvbuf_index[n_recv_pe] + 1));
1370 if (recvbuf ==
NULL) {
1380 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1382 if (rtc != 0)
goto error;
1388 for (i = 0; i < n_recv_pe; i++) {
1389 map_dst[i]->
id = (
int *)
HECMW_calloc(map_dst[i]->n,
sizeof(
int));
1390 if (map_dst[i]->
id ==
NULL) {
1394 for (j = 0; j < map_dst[i]->
n; j++) {
1395 map_dst[i]->
id[j] = recvbuf[recvbuf_index[i] + j];
1418 static int gather_n_positive_s2d(
struct map_info **map_src,
1423 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1424 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
1433 n_send_pe = comm_dst->
psize;
1436 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1437 if (send_pe ==
NULL) {
1441 for (i = 0; i < n_send_pe; i++) {
1442 send_pe[i] = comm_dst->
ranks[i];
1446 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1447 if (sendbuf_index ==
NULL) {
1451 for (i = 0; i < n_send_pe; i++) {
1452 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1456 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_index[n_send_pe] + 1));
1457 if (sendbuf ==
NULL) {
1461 for (i = 0; i < comm_dst->
psize; i++) {
1462 for (j = 0; j < map_src[i]->
n; j++) {
1463 sendbuf[sendbuf_index[i] + j] = map_src[i]->
n_positive[j];
1473 n_recv_pe = comm_src->
psize;
1476 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1477 if (recv_pe ==
NULL) {
1481 for (i = 0; i < n_recv_pe; i++) {
1482 recv_pe[i] = comm_src->
ranks[i];
1486 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1487 if (recvbuf_index ==
NULL) {
1491 for (i = 0; i < n_recv_pe; i++) {
1492 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1496 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (recvbuf_index[n_recv_pe] + 1));
1497 if (recvbuf ==
NULL) {
1507 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1509 if (rtc != 0)
goto error;
1515 for (i = 0; i < n_recv_pe; i++) {
1517 if (map_dst[i]->n_positive ==
NULL) {
1521 for (j = 0; j < map_dst[i]->
n; j++) {
1522 map_dst[i]->
n_positive[j] = recvbuf[recvbuf_index[i] + j];
1545 static int gather_dot_product_s2d(
struct map_info **map_src,
1550 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1551 int *sendbuf_index =
NULL, *recvbuf_index =
NULL;
1552 double *sendbuf =
NULL, *recvbuf =
NULL;
1560 n_send_pe = comm_dst->
psize;
1563 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1564 if (send_pe ==
NULL) {
1568 for (i = 0; i < n_send_pe; i++) {
1569 send_pe[i] = comm_dst->
ranks[i];
1573 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1574 if (sendbuf_index ==
NULL) {
1578 for (i = 0; i < n_send_pe; i++) {
1579 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1584 (
double *)
HECMW_malloc(
sizeof(
double) * (sendbuf_index[n_send_pe] + 1));
1585 if (sendbuf ==
NULL) {
1589 for (i = 0; i < comm_dst->
psize; i++) {
1590 for (j = 0; j < map_src[i]->
n; j++) {
1591 sendbuf[sendbuf_index[i] + j] = map_src[i]->
dot_product[j];
1601 n_recv_pe = comm_src->
psize;
1604 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1605 if (recv_pe ==
NULL) {
1609 for (i = 0; i < n_recv_pe; i++) {
1610 recv_pe[i] = comm_src->
ranks[i];
1614 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1615 if (recvbuf_index ==
NULL) {
1619 for (i = 0; i < n_recv_pe; i++) {
1620 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1625 (
double *)
HECMW_malloc(
sizeof(
double) * recvbuf_index[n_recv_pe] + 1);
1626 if (recvbuf ==
NULL) {
1636 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1638 if (rtc != 0)
goto error;
1644 for (i = 0; i < n_recv_pe; i++) {
1647 if (map_dst[i]->dot_product ==
NULL) {
1651 for (j = 0; j < map_dst[i]->
n; j++) {
1652 map_dst[i]->
dot_product[j] = recvbuf[recvbuf_index[i] + j];
1675 static int gather_distance_s2d(
struct map_info **map_src,
1680 int n_send_pe = 0, n_recv_pe = 0, *send_pe =
NULL, *recv_pe =
NULL;
1681 int *sendbuf_index =
NULL, *recvbuf_index =
NULL;
1682 double *sendbuf =
NULL, *recvbuf =
NULL;
1690 n_send_pe = comm_dst->
psize;
1693 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
1694 if (send_pe ==
NULL) {
1698 for (i = 0; i < n_send_pe; i++) {
1699 send_pe[i] = comm_dst->
ranks[i];
1703 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
1704 if (sendbuf_index ==
NULL) {
1708 for (i = 0; i < n_send_pe; i++) {
1709 sendbuf_index[i + 1] = sendbuf_index[i] + map_src[i]->
n;
1714 (
double *)
HECMW_malloc(
sizeof(
double) * (sendbuf_index[n_send_pe] + 1));
1715 if (sendbuf ==
NULL) {
1719 for (i = 0; i < comm_dst->
psize; i++) {
1720 for (j = 0; j < map_src[i]->
n; j++) {
1721 sendbuf[sendbuf_index[i] + j] = map_src[i]->
distance[j];
1729 n_recv_pe = comm_src->
psize;
1732 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
1733 if (recv_pe ==
NULL) {
1737 for (i = 0; i < n_recv_pe; i++) {
1738 recv_pe[i] = comm_src->
ranks[i];
1742 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
1743 if (recvbuf_index ==
NULL) {
1747 for (i = 0; i < n_recv_pe; i++) {
1748 recvbuf_index[i + 1] = recvbuf_index[i] + map_dst[i]->
n;
1753 (
double *)
HECMW_malloc(
sizeof(
double) * (recvbuf_index[n_recv_pe] + 1));
1754 if (recvbuf ==
NULL) {
1764 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
1766 if (rtc != 0)
goto error;
1772 for (i = 0; i < n_recv_pe; i++) {
1775 if (map_dst[i]->distance ==
NULL) {
1779 for (j = 0; j < map_dst[i]->
n; j++) {
1780 map_dst[i]->
distance[j] = recvbuf[recvbuf_index[i] + j];
1805 static int gather_map_data_s2d(
1810 int map_type, rtc, i;
1813 for (i = 0; i < comm_src->
psize; i++) {
1814 map_dst[i] = alloc_struct_map_info();
1815 if (map_dst[i] ==
NULL)
goto error;
1817 map_dst[i]->
n = mapped_point->
n;
1825 if (gather_id_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1827 if (gather_n_positive_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1829 if (gather_dot_product_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1831 if (gather_distance_s2d(map_src, comm_src, comm_dst, intercomm, map_dst))
1843 for (i = 0; i < comm_src->
psize; i++) {
1844 free_struct_map_info(map_dst[i]);
1857 double _dot_product, _distance;
1858 int _n_positive, _item, pe_index, index, size, rtc, n, i, j;
1862 if (mapping_data_list ==
NULL) {
1866 for (i = 0; i < comm_src->
psize; i++) {
1868 mapping_data_list[i].
id = -1;
1869 mapping_data_list[i].
item = -1;
1872 for (n = 0, i = 0; i < mapped_point->
n; i++) {
1875 for (j = 0; j < comm_src->
psize; j++) {
1876 if (map_dst[j]->n_positive[i] >= 0) {
1877 rtc = compare_mapping_info(
1878 _n_positive, _dot_product, _distance, map_dst[j]->n_positive[i],
1879 map_dst[j]->dot_product[i], map_dst[j]->distance[i]);
1882 _item = map_dst[j]->
id[i];
1885 _distance = map_dst[j]->
distance[i];
1890 if (_n_positive >= 0) {
1896 p->next = mapping_data_list[pe_index].
next;
1897 p->
id = mapped_point->
id[n++];
1899 mapping_data_list[pe_index].
next = p;
1903 return mapping_data_list;
1906 if (mapping_data_list) {
1907 for (i = 0; i < comm_src->
psize; i++) {
1908 free_link_list_map(mapping_data_list[i].
next);
1918 static int set_n_neighbor_pe_import(
1924 for (n = 0, i = 0; i < comm_src->
psize; i++) {
1925 if (mapping_data_list[i].
next) n++;
1945 for (n = 0, i = 0; i < comm_src->
psize; i++) {
1946 if (mapping_data_list[i].
next) {
1968 for (m = 0, n = 0, i = 0; i < comm_src->
psize; i++) {
1969 if (mapping_data_list[i].
next) {
1970 for (p = mapping_data_list[i].
next; p; p = p->
next) {
1994 for (n = 0, i = 0; i < comm_src->
psize; i++) {
1995 if (mapping_data_list[i].
next) {
1996 for (p = mapping_data_list[i].
next; p; p = p->
next) {
2012 int *export_data =
NULL;
2017 if (export_data ==
NULL) {
2022 for (n = 0, i = 0; i < comm_src->
psize; i++) {
2023 if (mapping_data_list[i].
next) {
2024 for (p = mapping_data_list[i].
next; p; p = p->
next) {
2025 export_data[n++] = p->
item;
2034 static int set_neighbor_info_import(
2041 if (set_n_neighbor_pe_import(inter_tbl, comm_src, mapping_data_list))
2045 if (set_neighbor_pe_import(inter_tbl, comm_src, mapping_data_list))
return -1;
2048 if (set_import_index(inter_tbl, comm_src, mapping_data_list))
return -1;
2051 if (set_import_item(inter_tbl, comm_src, mapping_data_list))
return -1;
2058 static int set_neighbor_pe_export(
2064 int n_send_pe = 0, n_recv_pe = 0;
2065 int *send_pe =
NULL, *recv_pe =
NULL;
2066 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
2068 int size, rtc, n, i;
2075 n_send_pe = comm_src->
psize;
2078 send_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_send_pe);
2079 if (send_pe ==
NULL) {
2083 for (i = 0; i < comm_src->
psize; i++) {
2084 send_pe[i] = comm_src->
ranks[i];
2088 sendbuf_index = (
int *)
HECMW_calloc(n_send_pe + 1,
sizeof(
int));
2089 if (sendbuf_index ==
NULL) {
2093 for (i = 0; i < n_send_pe; i++) {
2094 sendbuf_index[i + 1] = sendbuf_index[i] + 1;
2098 sendbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (sendbuf_index[n_send_pe] + 1));
2099 if (sendbuf ==
NULL) {
2103 for (i = 0; i < n_send_pe; i++) {
2104 if (mapping_data_list[i].
next) {
2117 n_recv_pe = comm_dst->
psize;
2120 recv_pe = (
int *)
HECMW_malloc(
sizeof(
int) * n_recv_pe);
2121 if (recv_pe ==
NULL) {
2125 for (i = 0; i < comm_dst->
psize; i++) {
2126 recv_pe[i] = comm_dst->
ranks[i];
2130 recvbuf_index = (
int *)
HECMW_calloc(n_recv_pe + 1,
sizeof(
int));
2131 if (recvbuf_index ==
NULL) {
2135 for (i = 0; i < n_recv_pe; i++) {
2136 recvbuf_index[i + 1] = recvbuf_index[i] + 1;
2140 recvbuf = (
int *)
HECMW_malloc(
sizeof(
int) * (recvbuf_index[n_recv_pe] + 1));
2141 if (recvbuf ==
NULL) {
2149 n_recv_pe, recv_pe, recvbuf_index, recvbuf,
2151 if (rtc != 0)
goto error;
2157 for (n = 0, i = 0; i < comm_dst->
psize; i++) {
2158 if (recvbuf[i] > 0) n++;
2169 for (n = 0, i = 0; i < comm_dst->
psize; i++) {
2170 if (recvbuf[i] > 0) {
2200 int *sendbuf_index =
NULL, *recvbuf_index =
NULL, *sendbuf =
NULL,
2211 if (sendbuf_index ==
NULL) {
2216 sendbuf_index[i + 1] = sendbuf_index[i] + 1;
2222 if (sendbuf ==
NULL) {
2238 if (recvbuf_index ==
NULL) {
2243 recvbuf_index[i + 1] = recvbuf_index[i] + 1;
2249 if (recvbuf ==
NULL) {
2267 if (rtc != 0)
goto error;
2318 size =
sizeof(int) *
2335 if (rtc != 0)
goto error;
2350 int *export_data =
NULL;
2355 if (inter_tbl ==
NULL)
goto error;
2359 mapping_data_list = set_mapping_surf(mapped_point, comm_src, map_dst);
2360 if (mapping_data_list ==
NULL)
goto error;
2362 rtc = set_neighbor_info_import(inter_tbl, mapping_data_list, comm_src);
2365 export_data = set_export_data(inter_tbl, comm_src, mapping_data_list);
2366 if (export_data ==
NULL)
goto error;
2370 rtc = set_neighbor_pe_export(inter_tbl, comm_src, comm_dst, intercomm,
2374 rtc = set_export_index(inter_tbl, comm_src, comm_dst, intercomm);
2377 rtc = set_export_item(inter_tbl, comm_src, comm_dst, intercomm, export_data);
2405 int **is_candidate =
NULL;
2411 if (all_mapped_point ==
NULL) {
2415 for (i = 0; i < comm_dst->
psize; i++) {
2416 all_mapped_point[i] =
NULL;
2420 if (is_candidate ==
NULL) {
2424 for (i = 0; i < comm_dst->
psize; i++) {
2425 is_candidate[i] =
NULL;
2429 rtc = bcast_mapped_point_d2s(mapped_point, comm_src, comm_dst, intercomm,
2433 rtc = set_candidate_node(bbox_src, bbox_dst, comm_src, comm_dst, intercomm,
2434 all_mapped_point, is_candidate);
2441 if (map_src ==
NULL) {
2445 for (i = 0; i < comm_dst->
psize; i++) {
2448 for (i = 0; i < comm_dst->
psize; i++) {
2449 map_src[i] = alloc_struct_map_info();
2450 if (map_src[i] ==
NULL)
goto error;
2456 rtc = mapping_in_src(mesh_src, boundary_src, bbox_src, bgcell_src, comm_dst,
2457 all_mapped_point, is_candidate, map_src);
2461 if (all_mapped_point) {
2462 for (i = 0; i < comm_dst->
psize; i++) {
2468 for (i = 0; i < comm_dst->
psize; i++) {
2478 if (map_dst ==
NULL) {
2482 for (i = 0; i < comm_src->
psize; i++) {
2487 rtc = gather_map_data_s2d(mapped_point, map_src, comm_src, comm_dst,
2488 intercomm, map_dst);
2493 set_inter_iftable(comm_src, comm_dst, intercomm, map_dst, mapped_point);
2494 if (inter_tbl ==
NULL)
goto error;
2499 if (all_mapped_point) {
2500 for (i = 0; i < comm_dst->
psize; i++) {
2506 for (i = 0; i < comm_dst->
psize; i++) {