Debian Codegraph @

packages/seacas/libraries/exodus/src/ex_put_cmap_params_cc.c

raw
1 /*
2 * Copyright(C) 1999-2022 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8 /*****************************************************************************/
9 /*****************************************************************************/
10 /*****************************************************************************/
11 /* Function(s) contained in this file:
12 * ex_put_cmap_params_cc()
13 *****************************************************************************
14 * This function outputs the concatenated list of communication map
15 * parameters.
16 *****************************************************************************
17 * Variable Index:
18 * exoid - The NetCDF ID of an already open NemesisI file.
19 * node_cmap_ids - Pointer to vector of nodal communication
20 * set IDs.
21 * node_cmap_node_cnts - Pointer to a vector which contains a count of
22 * the number of FEM nodes for each nodal
23 * communication map.
24 * elem_cmap_ids - Pointer to vector for retrieval of elemental
25 * communication set IDs.
26 * elem_cmap_elem_cnts - Pointer to a vector which contains a count of
27 * the number of FEM elements for each elemental
28 * communication map.
29 * proc_ids - The processor the file being read was written
30 * for.
31 */
32 /*****************************************************************************/
33 /*****************************************************************************/
34 /*****************************************************************************/
35 #include <exodusII.h> // for ex_err, etc
36 #include <exodusII_int.h> // for EX_FATAL, exi_leavedef, etc
37
38 int ex_put_cmap_params_cc(int exoid, const void_int *node_cmap_ids,
39 const void_int *node_cmap_node_cnts, const void_int *node_proc_ptrs,
40 const void_int *elem_cmap_ids, const void_int *elem_cmap_elem_cnts,
41 const void_int *elem_proc_ptrs)
42 {
43 size_t num_n_comm_maps, num_e_comm_maps;
44 int status, n_varid[2], e_varid[2];
45 int varid, n_dimid[1], e_dimid[1];
46 int n_varid_idx, e_varid_idx;
47 int num_icm;
48 size_t start[1], count[1];
49 size_t iproc;
50
51 long long nl_ecnt_cmap, nl_ncnt_cmap;
52 void_int *n_var_idx = NULL;
53 void_int *e_var_idx = NULL;
54
55 int nmstat;
56
57 char errmsg[MAX_ERR_LENGTH];
58 int index_type, bulk_type;
59 /*-----------------------------Execution begins-----------------------------*/
60
61 EX_FUNC_ENTER();
62 if (exi_check_valid_file_id(exoid, __func__) == EX_FATAL) {
63 EX_FUNC_LEAVE(EX_FATAL);
64 }
65
66 /* See if using NC_FORMAT_NETCDF4 format... */
67 int format;
68 nc_inq_format(exoid, &format);
69 if ((ex_int64_status(exoid) & EX_BULK_INT64_DB) || (format == NC_FORMAT_NETCDF4)) {
70 index_type = NC_INT64;
71 }
72 else {
73 index_type = NC_INT;
74 }
75 if (ex_int64_status(exoid) & EX_BULK_INT64_DB) {
76 bulk_type = NC_INT64;
77 }
78 else {
79 bulk_type = NC_INT;
80 }
81
82 /* Get the number of processors in the file */
83 if ((status = nc_inq_dimid(exoid, DIM_NUM_PROCS_F, &n_dimid[0])) != NC_NOERR) {
84 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get dimension ID for \"%s\" in file ID %d",
85 DIM_NUM_PROCS_F, exoid);
86 ex_err_fn(exoid, __func__, errmsg, status);
87 EX_FUNC_LEAVE(EX_FATAL);
88 }
89
90 size_t num_procs_in_file;
91 if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_procs_in_file)) != NC_NOERR) {
92 snprintf(errmsg, MAX_ERR_LENGTH,
93 "ERROR: failed to find length of dimension \"%s\" in file ID %d", DIM_NUM_PROCS_F,
94 exoid);
95 ex_err_fn(exoid, __func__, errmsg, status);
96 EX_FUNC_LEAVE(EX_FATAL);
97 }
98
99 /*
100 * since I cannot get variables while in define mode, I need to
101 * get the cmap information index variables before I go into
102 * define mode
103 */
104
105 /* Check to see if there are nodal communications maps in the file */
106 if (nc_inq_dimid(exoid, DIM_NUM_N_CMAPS, &n_dimid[0]) != NC_NOERR) {
107 num_n_comm_maps = 0;
108 }
109 else {
110 if ((status = nc_inq_dimlen(exoid, n_dimid[0], &num_n_comm_maps)) != NC_NOERR) {
111 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find length of dimension \"%s\" in \
112 file ID %d",
113 DIM_NUM_N_CMAPS, exoid);
114 ex_err_fn(exoid, __func__, errmsg, status);
115 EX_FUNC_LEAVE(EX_FATAL);
116 }
117 }
118
119 if (num_n_comm_maps > 0) {
120 /* Get the variable ID for the comm map index vector */
121 if ((status = nc_inq_varid(exoid, VAR_N_COMM_INFO_IDX, &n_varid_idx)) != NC_NOERR) {
122 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
123 VAR_N_COMM_INFO_IDX, exoid);
124 ex_err_fn(exoid, __func__, errmsg, status);
125 EX_FUNC_LEAVE(EX_FATAL);
126 }
127
128 /* allocate space for the index variable */
129 if (index_type == NC_INT64) {
130 n_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long));
131 }
132 else {
133 n_var_idx = malloc((num_procs_in_file + 1) * sizeof(int));
134 }
135 if (!n_var_idx) {
136 snprintf(errmsg, MAX_ERR_LENGTH,
137 "ERROR: insufficient memory to read index variable from file ID %d", exoid);
138 ex_err_fn(exoid, __func__, errmsg, EX_MSG);
139 EX_FUNC_LEAVE(EX_FATAL);
140 }
141
142 /* and set the last value of the index */
143
144 /* get the communication map info index */
145 if (index_type == NC_INT64) {
146 ((long long *)n_var_idx)[0] = 0;
147 status = nc_get_var_longlong(exoid, n_varid_idx, &((long long *)n_var_idx)[1]);
148 }
149 else {
150 ((int *)n_var_idx)[0] = 0;
151 status = nc_get_var_int(exoid, n_varid_idx, &((int *)n_var_idx)[1]);
152 }
153 if (status != NC_NOERR) {
154 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
155 VAR_N_COMM_INFO_IDX, exoid);
156 ex_err_fn(exoid, __func__, errmsg, status);
157 free(n_var_idx);
158 EX_FUNC_LEAVE(EX_FATAL);
159 }
160 } /* "if (num_n_comm_maps > 0)" */
161
162 /* Check to see if there are elemental communications maps in the file */
163 if (nc_inq_dimid(exoid, DIM_NUM_E_CMAPS, &e_dimid[0]) != NC_NOERR) {
164 num_e_comm_maps = 0;
165 }
166 else {
167 if ((status = nc_inq_dimlen(exoid, e_dimid[0], &num_e_comm_maps)) != NC_NOERR) {
168 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find length of dimension \"%s\" in \
169 file ID %d",
170 DIM_NUM_E_CMAPS, exoid);
171 ex_err_fn(exoid, __func__, errmsg, status);
172 EX_FUNC_LEAVE(EX_FATAL);
173 }
174 }
175
176 if (num_e_comm_maps > 0) {
177 /* Get the variable ID for the comm map index vector */
178 if ((status = nc_inq_varid(exoid, VAR_E_COMM_INFO_IDX, &e_varid_idx)) != NC_NOERR) {
179 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
180 VAR_E_COMM_INFO_IDX, exoid);
181 ex_err_fn(exoid, __func__, errmsg, status);
182 EX_FUNC_LEAVE(EX_FATAL);
183 }
184
185 /* allocate space for the index variable */
186 if (index_type == NC_INT64) {
187 e_var_idx = malloc((num_procs_in_file + 1) * sizeof(long long));
188 }
189 else {
190 e_var_idx = malloc((num_procs_in_file + 1) * sizeof(int));
191 }
192 if (!e_var_idx) {
193 snprintf(errmsg, MAX_ERR_LENGTH,
194 "ERROR: insufficient memory to read index variable from file ID %d", exoid);
195 ex_err_fn(exoid, __func__, errmsg, EX_MEMFAIL);
196 EX_FUNC_LEAVE(EX_FATAL);
197 }
198
199 /* get the communication map info index */
200 if (index_type == NC_INT64) {
201 ((long long *)e_var_idx)[0] = 0;
202 status = nc_get_var_longlong(exoid, e_varid_idx, &((long long *)e_var_idx)[1]);
203 }
204 else {
205 ((int *)e_var_idx)[0] = 0;
206 status = nc_get_var_int(exoid, e_varid_idx, &((int *)e_var_idx)[1]);
207 }
208 if (status != NC_NOERR) {
209 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to get variable \"%s\" from file ID %d",
210 VAR_E_COMM_INFO_IDX, exoid);
211 ex_err_fn(exoid, __func__, errmsg, status);
212 free(e_var_idx);
213 EX_FUNC_LEAVE(EX_FATAL);
214 }
215 } /* "if (num_e_comm_maps >0)" */
216
217 /* Put NetCDF file into define mode */
218 if ((status = exi_redef(exoid, __func__)) != NC_NOERR) {
219 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file ID %d into define mode", exoid);
220 ex_err_fn(exoid, __func__, errmsg, status);
221 EX_FUNC_LEAVE(EX_FATAL);
222 }
223
224 /*
225 * Add dimensions for the size of the number of nodal
226 * communication maps.
227 */
228 if (num_n_comm_maps > 0) {
229 /* add the communications data index variable */
230 if ((status = nc_def_var(exoid, VAR_N_COMM_DATA_IDX, index_type, 1, n_dimid, &n_varid_idx)) !=
231 NC_NOERR) {
232 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
233 VAR_N_COMM_DATA_IDX, exoid);
234 ex_err_fn(exoid, __func__, errmsg, status);
235 /* Leave define mode before returning */
236 exi_leavedef(exoid, __func__);
237
238 EX_FUNC_LEAVE(EX_FATAL);
239 }
240
241 /* now add up all of the nodal communications maps */
242 size_t ncnt_cmap = 0;
243 for (iproc = 0; iproc < num_procs_in_file; iproc++) {
244 if (index_type == NC_INT64) {
245 num_icm = ((int64_t *)n_var_idx)[iproc + 1] - ((int64_t *)n_var_idx)[iproc];
246 }
247 else {
248 num_icm = ((int *)n_var_idx)[iproc + 1] - ((int *)n_var_idx)[iproc];
249 }
250 for (int icm = 0; icm < num_icm; icm++) {
251 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
252 ncnt_cmap += ((int64_t *)node_cmap_node_cnts)[((int64_t *)node_proc_ptrs)[iproc] + icm];
253 }
254 else {
255 ncnt_cmap += ((int *)node_cmap_node_cnts)[((int *)node_proc_ptrs)[iproc] + icm];
256 }
257 }
258 }
259
260 if ((status = nc_def_dim(exoid, DIM_NCNT_CMAP, ncnt_cmap, &n_dimid[0])) != NC_NOERR) {
261 snprintf(errmsg, MAX_ERR_LENGTH,
262 "ERROR: failed to add dimension for \"%s\" of size %zu in file ID %d", DIM_NCNT_CMAP,
263 ncnt_cmap, exoid);
264 ex_err_fn(exoid, __func__, errmsg, status);
265 /* Leave define mode before returning */
266 exi_leavedef(exoid, __func__);
267
268 EX_FUNC_LEAVE(EX_FATAL);
269 }
270
271 /* Define variables for the nodal IDS and processor vectors */
272 if ((status = nc_def_var(exoid, VAR_N_COMM_NIDS, bulk_type, 1, n_dimid, &varid)) != NC_NOERR) {
273 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
274 VAR_N_COMM_NIDS, exoid);
275 ex_err_fn(exoid, __func__, errmsg, status);
276 /* Leave define mode before returning */
277 exi_leavedef(exoid, __func__);
278
279 EX_FUNC_LEAVE(EX_FATAL);
280 }
281 exi_compress_variable(exoid, varid, 1);
282
283 if ((status = nc_def_var(exoid, VAR_N_COMM_PROC, NC_INT, 1, n_dimid, &varid)) != NC_NOERR) {
284 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
285 VAR_N_COMM_PROC, exoid);
286 ex_err_fn(exoid, __func__, errmsg, status);
287 /* Leave define mode before returning */
288 exi_leavedef(exoid, __func__);
289
290 EX_FUNC_LEAVE(EX_FATAL);
291 }
292 exi_compress_variable(exoid, varid, 1);
293
294 } /* End "if (num_n_comm_maps > 0)" */
295
296 /*
297 * Add dimensions for the size of the number of elemental
298 * communication maps.
299 */
300 if (num_e_comm_maps > 0) {
301 /* add the communications data index variable */
302 if ((status = nc_def_var(exoid, VAR_E_COMM_DATA_IDX, index_type, 1, e_dimid, &e_varid_idx)) !=
303 NC_NOERR) {
304 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
305 VAR_E_COMM_DATA_IDX, exoid);
306 ex_err_fn(exoid, __func__, errmsg, status);
307 /* Leave define mode before returning */
308 exi_leavedef(exoid, __func__);
309
310 EX_FUNC_LEAVE(EX_FATAL);
311 }
312
313 /* now add up all of the nodal communications maps */
314 size_t ecnt_cmap = 0;
315 for (iproc = 0; iproc < num_procs_in_file; iproc++) {
316 if (index_type == NC_INT64) {
317 num_icm = ((int64_t *)e_var_idx)[iproc + 1] - ((int64_t *)e_var_idx)[iproc];
318 }
319 else {
320 num_icm = ((int *)e_var_idx)[iproc + 1] - ((int *)e_var_idx)[iproc];
321 }
322 for (int icm = 0; icm < num_icm; icm++) {
323 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
324 ecnt_cmap += ((int64_t *)elem_cmap_elem_cnts)[((int64_t *)elem_proc_ptrs)[iproc] + icm];
325 }
326 else {
327 ecnt_cmap += ((int *)elem_cmap_elem_cnts)[((int *)elem_proc_ptrs)[iproc] + icm];
328 }
329 }
330 }
331
332 /* Add dimensions for elemental communications maps */
333 if ((status = nc_def_dim(exoid, DIM_ECNT_CMAP, ecnt_cmap, &e_dimid[0])) != NC_NOERR) {
334 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add dimension for \"%s\" in file ID %d",
335 DIM_ECNT_CMAP, exoid);
336 ex_err_fn(exoid, __func__, errmsg, status);
337 /* Leave define mode before returning */
338 exi_leavedef(exoid, __func__);
339
340 EX_FUNC_LEAVE(EX_FATAL);
341 }
342
343 /* Define variables for the element IDS and processor vectors */
344 if ((status = nc_def_var(exoid, VAR_E_COMM_EIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) {
345 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
346 VAR_E_COMM_EIDS, exoid);
347 ex_err_fn(exoid, __func__, errmsg, status);
348 /* Leave define mode before returning */
349 exi_leavedef(exoid, __func__);
350
351 EX_FUNC_LEAVE(EX_FATAL);
352 }
353 exi_compress_variable(exoid, varid, 1);
354
355 if ((status = nc_def_var(exoid, VAR_E_COMM_PROC, NC_INT, 1, e_dimid, &varid)) != NC_NOERR) {
356 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
357 VAR_E_COMM_PROC, exoid);
358 ex_err_fn(exoid, __func__, errmsg, status);
359 /* Leave define mode before returning */
360 exi_leavedef(exoid, __func__);
361
362 EX_FUNC_LEAVE(EX_FATAL);
363 }
364 exi_compress_variable(exoid, varid, 1);
365
366 if ((status = nc_def_var(exoid, VAR_E_COMM_SIDS, bulk_type, 1, e_dimid, &varid)) != NC_NOERR) {
367 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to add variable \"%s\" in file ID %d",
368 VAR_E_COMM_SIDS, exoid);
369 ex_err_fn(exoid, __func__, errmsg, status);
370 /* Leave define mode before returning */
371 exi_leavedef(exoid, __func__);
372
373 EX_FUNC_LEAVE(EX_FATAL);
374 }
375 exi_compress_variable(exoid, varid, 1);
376
377 } /* End "if (num_e_comm_maps > 0)" */
378
379 /* Exit define mode */
380 exi_leavedef(exoid, __func__);
381
382 /* Set the status of the nodal communication maps */
383 if (num_n_comm_maps > 0) {
384
385 /* need to get the two "n_comm_*" variable ids */
386
387 if ((status = nc_inq_varid(exoid, VAR_N_COMM_STAT, &n_varid[0])) != NC_NOERR) {
388 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
389 VAR_N_COMM_STAT, exoid);
390 ex_err_fn(exoid, __func__, errmsg, status);
391 EX_FUNC_LEAVE(EX_FATAL);
392 }
393
394 /* Get the variable ID for the comm map IDs vector */
395 if ((status = nc_inq_varid(exoid, VAR_N_COMM_IDS, &n_varid[1])) != NC_NOERR) {
396 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
397 VAR_N_COMM_IDS, exoid);
398 ex_err_fn(exoid, __func__, errmsg, status);
399 EX_FUNC_LEAVE(EX_FATAL);
400 }
401
402 /* reset the index variable */
403 nl_ncnt_cmap = 0;
404
405 for (iproc = 0; iproc < num_procs_in_file; iproc++) {
406 size_t proc_ptr;
407 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
408 proc_ptr = ((int64_t *)node_proc_ptrs)[iproc];
409 }
410 else {
411 proc_ptr = ((int *)node_proc_ptrs)[iproc];
412 }
413
414 if (index_type == NC_INT64) {
415 num_icm = ((int64_t *)n_var_idx)[iproc + 1] - ((int64_t *)n_var_idx)[iproc];
416 }
417 else {
418 num_icm = ((int *)n_var_idx)[iproc + 1] - ((int *)n_var_idx)[iproc];
419 }
420 for (int icm = 0; icm < num_icm; icm++) {
421 size_t cnt;
422 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
423 cnt = ((int64_t *)node_cmap_node_cnts)[proc_ptr + icm];
424 }
425 else {
426 cnt = ((int *)node_cmap_node_cnts)[proc_ptr + icm];
427 }
428
429 if (index_type == NC_INT64) {
430 start[0] = ((int64_t *)n_var_idx)[iproc] + icm;
431 }
432 else {
433 start[0] = ((int *)n_var_idx)[iproc] + icm;
434 }
435 if (cnt > 0) {
436 nmstat = 1;
437 }
438 else {
439 nmstat = 0;
440 }
441
442 if ((status = nc_put_var1_int(exoid, n_varid[0], start, &nmstat)) != NC_NOERR) {
443 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to output variable in file ID %d", exoid);
444 ex_err_fn(exoid, __func__, errmsg, status);
445 EX_FUNC_LEAVE(EX_FATAL);
446 }
447
448 /* increment to the next starting position */
449 nl_ncnt_cmap += cnt;
450
451 /* fill the data index variable */
452 status = nc_put_var1_longlong(exoid, n_varid_idx, start, &nl_ncnt_cmap);
453
454 if (status != NC_NOERR) {
455 snprintf(errmsg, MAX_ERR_LENGTH,
456 "ERROR: failed to output int elem map index in file ID %d", exoid);
457 ex_err_fn(exoid, __func__, errmsg, status);
458 EX_FUNC_LEAVE(EX_FATAL);
459 }
460 } /* End "for(icm=0; icm < num_icm; icm++)" */
461
462 if (num_icm > 0) {
463 /* Output the nodal comm map IDs */
464 if (index_type == NC_INT64) {
465 start[0] = ((int64_t *)n_var_idx)[iproc];
466 }
467 else {
468 start[0] = ((int *)n_var_idx)[iproc];
469 }
470 count[0] = num_icm;
471 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
472 status = nc_put_vara_longlong(exoid, n_varid[1], start, count,
473 &((long long *)node_cmap_ids)[proc_ptr]);
474 }
475 else {
476 status =
477 nc_put_vara_int(exoid, n_varid[1], start, count, &((int *)node_cmap_ids)[proc_ptr]);
478 }
479 if (status != NC_NOERR) {
480 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable in file ID %d", exoid);
481 ex_err_fn(exoid, __func__, errmsg, status);
482
483 EX_FUNC_LEAVE(EX_FATAL);
484 }
485 }
486 } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */
487
488 /* free up memory for index */
489 free(n_var_idx);
490
491 } /* End "if (num_n_comm_maps > 0)" */
492
493 /* Set the status of the elemental communication maps */
494 if (num_e_comm_maps > 0) {
495
496 /* need to get the two "e_comm_*" variables" */
497
498 /* Get variable ID for elemental status vector */
499 if ((status = nc_inq_varid(exoid, VAR_E_COMM_STAT, &e_varid[0])) != NC_NOERR) {
500 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
501 VAR_E_COMM_STAT, exoid);
502 ex_err_fn(exoid, __func__, errmsg, status);
503 EX_FUNC_LEAVE(EX_FATAL);
504 }
505
506 /* Get the variable ID for the elemental comm map IDs vector */
507 if ((status = nc_inq_varid(exoid, VAR_E_COMM_IDS, &e_varid[1])) != NC_NOERR) {
508 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find variable ID for \"%s\" in file ID %d",
509 VAR_E_COMM_IDS, exoid);
510 ex_err_fn(exoid, __func__, errmsg, status);
511 EX_FUNC_LEAVE(EX_FATAL);
512 }
513
514 /* reset the index variable */
515 nl_ecnt_cmap = 0;
516
517 for (iproc = 0; iproc < num_procs_in_file; iproc++) {
518 size_t proc_ptr;
519 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
520 proc_ptr = ((int64_t *)elem_proc_ptrs)[iproc];
521 }
522 else {
523 proc_ptr = ((int *)elem_proc_ptrs)[iproc];
524 }
525 if (index_type == NC_INT64) {
526 num_icm = ((int64_t *)e_var_idx)[iproc + 1] - ((int64_t *)e_var_idx)[iproc];
527 }
528 else {
529 num_icm = ((int *)e_var_idx)[iproc + 1] - ((int *)e_var_idx)[iproc];
530 }
531 for (int icm = 0; icm < num_icm; icm++) {
532
533 size_t cnt;
534 if (ex_int64_status(exoid) & EX_BULK_INT64_API) {
535 cnt = ((int64_t *)elem_cmap_elem_cnts)[proc_ptr + icm];
536 }
537 else {
538 cnt = ((int *)elem_cmap_elem_cnts)[proc_ptr + icm];
539 }
540
541 if (index_type == NC_INT64) {
542 start[0] = ((int64_t *)e_var_idx)[iproc] + icm;
543 }
544 else {
545 start[0] = ((int *)e_var_idx)[iproc] + icm;
546 }
547 if (cnt > 0) {
548 nmstat = 1;
549 }
550 else {
551 nmstat = 0;
552 }
553
554 if ((status = nc_put_var1_int(exoid, e_varid[0], start, &nmstat)) != NC_NOERR) {
555 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: unable to output variable in file ID %d", exoid);
556 ex_err_fn(exoid, __func__, errmsg, status);
557 EX_FUNC_LEAVE(EX_FATAL);
558 }
559
560 /* increment to the next starting position */
561 nl_ecnt_cmap += cnt;
562
563 /* fill the data index variable */
564 status = nc_put_var1_longlong(exoid, e_varid_idx, start, &nl_ecnt_cmap);
565
566 if (status != NC_NOERR) {
567 snprintf(errmsg, MAX_ERR_LENGTH,
568 "ERROR: failed to output int elem map index in file ID %d", exoid);
569 ex_err_fn(exoid, __func__, errmsg, status);
570 EX_FUNC_LEAVE(EX_FATAL);
571 }
572 } /* End "for(icm=0; icm < num_icm; icm++)" */
573
574 if (num_icm > 0) {
575 /* Output the elemental comm map IDs */
576 if (index_type == NC_INT64) {
577 start[0] = ((int64_t *)e_var_idx)[iproc];
578 }
579 else {
580 start[0] = ((int *)e_var_idx)[iproc];
581 }
582 count[0] = num_icm;
583 if (ex_int64_status(exoid) & EX_IDS_INT64_API) {
584 status = nc_put_vara_longlong(exoid, e_varid[1], start, count,
585 &((long long *)elem_cmap_ids)[proc_ptr]);
586 }
587 else {
588 status =
589 nc_put_vara_int(exoid, e_varid[1], start, count, &((int *)elem_cmap_ids)[proc_ptr]);
590 }
591 if (status != NC_NOERR) {
592 snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to output variable in file ID %d", exoid);
593 ex_err_fn(exoid, __func__, errmsg, status);
594 EX_FUNC_LEAVE(EX_FATAL);
595 }
596 }
597 } /* End "for(iproc=0; iproc < num_procs_in_file; iproc++)" */
598
599 free(e_var_idx);
600
601 } /* End "if (num_e_comm_maps > 0)" */
602
603 EX_FUNC_LEAVE(EX_NOERR);
604 }