1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654 | #include <cstdio>
#include "CubitString.hpp"
#include "CubitMessage.hpp"
#include "DLList.hpp"
#include "RefEntity.hpp"
#include "RefFace.hpp"
#include "RefEdge.hpp"
#include "RefVertex.hpp"
#include "CubitEntity.hpp"
#include "Body.hpp"
#include "CastTo.hpp"
#include "CubitUtil.hpp"
#include "CADefines.hpp"
#include "CABodies.hpp"
#include "TDParallel.hpp"
#include "CAMergePartner.hpp"
#include "TDUniqueId.hpp"
#include "TopologyBridge.hpp"
#include "GeometryQueryTool.hpp"
#include "CGMReadParallel.hpp"
#include "CGMParallelConventions.h"
#include "CGMParallelComm.hpp"
#include "CubitCompat.hpp"
#include <iostream>
const bool CGM_read_parallel_debug = false;
enum CGMParallelActions {
PA_READ = 0,
PA_BROADCAST,
PA_DELETE_NONLOCAL,
PA_SCATTER,
PA_SCATTER_DELETE,
PA_BALANCE
};
enum CGMPartitionActions {
PT_GEOM_DIM = 0, PT_PAR_PART
};
const char *CGMParallelActionsNames[] = { "PARALLEL READ", "PARALLEL BROADCAST",
"PARALLEL DELETE NONLOCAL", "PARALLEL SCATTER" };
const char* CGMReadParallel::CGMparallelOptsNames[] = { "NONE", "READ",
"READ_DELETE", "BCAST", "BCAST_DELETE", "SCATTER", "SCATTER_DELETE",
"READ_PARALLEL", "FORMAT", "", 0 };
const char* CGMReadParallel::CGMpartitionOptsNames[] = { "NONE",
"GEOM_DIMENSION", "PARARELL_PARTITION", "", 0 };
CGMReadParallel::CGMReadParallel(GeometryQueryTool* gqt, CGMParallelComm *pc) :
m_gqt(gqt), m_pcomm(pc) {
if (!m_pcomm) {
m_pcomm = new CGMParallelComm();
}
m_bal_method = ROUND_ROBIN;
m_scatter = false;
m_rank = m_pcomm->proc_config().proc_rank();
m_proc_size = m_pcomm->proc_config().proc_size();
}
CubitStatus CGMReadParallel::load_file(const char *file_name,
const char *options, const char* set_tag_name, const int* set_tag_values,
int num_set_tag_values) {
CGMFileOptions opts(options);
// Get parallel settings
int parallel_mode;
CGMFOErrorCode result = opts.match_option("PARALLEL", CGMparallelOptsNames,
parallel_mode);
if (FO_FAILURE == result) {
PRINT_ERROR("Unexpected value for 'PARALLEL' option\n");
return CUBIT_FAILURE;
} else if (FO_ENTITY_NOT_FOUND == result) {
parallel_mode = 0;
}
bool surf_partition = false;
std::string partition_tag_name;
std::vector<int> partition_tag_vals;
// Get partition tag value(s), if any, and whether they're to be
result = opts.get_ints_option("PARTITION_VAL", partition_tag_vals);<--- result is assigned
// Get partition setting
result = opts.get_option("PARTITION", partition_tag_name);<--- result is overwritten
if (FO_ENTITY_NOT_FOUND == result || partition_tag_name.empty()) {
partition_tag_name = "GEOM_DIMENSION";
m_bal_method = ROUND_ROBIN;
} else {
// use geom dimension for partition
if (partition_tag_name == "GEOM_DIMENSION") {
int geom_dim = 0;<--- The scope of the variable 'geom_dim' can be reduced. [+]The scope of the variable 'geom_dim' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
for (std::vector<int>::iterator pit = partition_tag_vals.begin();
pit != partition_tag_vals.end(); pit++) {<--- Prefer prefix ++/-- operators for non-primitive types. [+]Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.
geom_dim = *pit;
if (geom_dim == 2)
surf_partition = true; // body & surface partition
else if (geom_dim == 3)
surf_partition = false; // body partition only
else {
PRINT_ERROR("Geometry dimension %d is not supported.\n", geom_dim);
return CUBIT_FAILURE;
}
}
}
// static partition, use chaco
else if (partition_tag_name == "PAR_PARTITION_STATIC") {
m_bal_method = PARTITION_STATIC;
}
// dynamic partition, use zoltan
else if (partition_tag_name == "PAR_PARTITION_DYNAMIC") {
m_bal_method = PARTITION_DYNAMIC;
}
// round-robin
result = opts.get_null_option("PARTITION_DISTRIBUTE");
if (FO_SUCCESS == result)
m_bal_method = ROUND_ROBIN;
}
// get MPI IO processor rank
int reader_rank;
result = opts.get_int_option("MPI_IO_RANK", reader_rank);
if (FO_ENTITY_NOT_FOUND == result)
reader_rank = 0;
else if (FO_SUCCESS != result) {
PRINT_ERROR("Unexpected value for 'MPI_IO_RANK' option\n");
return CUBIT_FAILURE;
}
m_pcomm->proc_config().set_master(reader_rank); // set master processor
bool reader = (reader_rank == (int) m_rank);
// now that we've parsed all the parallel options, make an instruction
// queue
std::vector<int> pa_vec;
switch (parallel_mode) {
case POPT_READ:
pa_vec.push_back(PA_READ);
pa_vec.push_back(PA_BALANCE);
break;
case POPT_DEFAULT:
case POPT_READ_DELETE:
pa_vec.push_back(PA_READ);
pa_vec.push_back(PA_BALANCE);
pa_vec.push_back(PA_DELETE_NONLOCAL);
break;
case POPT_BCAST:
if (reader) {
pa_vec.push_back(PA_READ);
pa_vec.push_back(PA_BALANCE);
}
pa_vec.push_back(PA_BROADCAST);
break;
case POPT_BCAST_DELETE:
if (reader) {
pa_vec.push_back(PA_READ);
pa_vec.push_back(PA_BALANCE);
}
pa_vec.push_back(PA_BROADCAST);
pa_vec.push_back(PA_DELETE_NONLOCAL);
break;
case PORT_SCATTER:
if (reader) {
pa_vec.push_back(PA_READ);
pa_vec.push_back(PA_BALANCE);
}
pa_vec.push_back(PA_SCATTER);
m_scatter = true;
break;
case POPT_FORMAT:
PRINT_ERROR("Access to format-specific parallel read not implemented.\n");
return CUBIT_FAILURE;
case POPT_READ_PARALLEL:
PRINT_ERROR("Partitioning for PARALLEL=READ_PARALLEL not supported yet.\n");
return CUBIT_FAILURE;
default:
return CUBIT_FAILURE;
}
return load_file(file_name, parallel_mode, partition_tag_name,
partition_tag_vals, pa_vec, opts, set_tag_name, set_tag_values,
num_set_tag_values, reader_rank, surf_partition);
}
CubitStatus CGMReadParallel::load_file(const char *file_name, int parallel_mode,
std::string &partition_tag_name, std::vector<int> &partition_tag_vals,
std::vector<int> &pa_vec, const CGMFileOptions &opts,
const char* set_tag_name, const int* set_tag_values,
const int num_set_tag_values, const int reader_rank,
const bool surf_partition) {
// actuate CA_BODIES and turn on auto flag for other attributes
CGMApp::instance()->attrib_manager()->register_attrib_type(CA_BODIES,
"bodies", "BODIES", &CABodies_creator, CUBIT_TRUE, CUBIT_TRUE, CUBIT_TRUE,
CUBIT_TRUE, CUBIT_TRUE, CUBIT_FALSE);
CGMApp::instance()->attrib_manager()->auto_flag(CUBIT_TRUE);
if (CGM_read_parallel_debug) {
DEBUG_FLAG(90, CUBIT_TRUE);
DEBUG_FLAG(138, CUBIT_TRUE);
}
// do the work by options
std::vector<int>::iterator vit;
int i;
for (i = 1, vit = pa_vec.begin(); vit != pa_vec.end(); vit++, i++) {<--- Prefer prefix ++/-- operators for non-primitive types. [+]Prefix ++/-- operators should be preferred for non-primitive types. Pre-increment/decrement can be more efficient than post-increment/decrement. Post-increment/decrement usually involves keeping a copy of the previous value around and adds a little extra code.
CubitStatus result = CUBIT_SUCCESS;
switch (*vit) {
//==================
case PA_READ:
double tStart, tEnd;
if (CGM_read_parallel_debug) {
std::cout << "Reading file " << file_name << std::endl;
tStart = MPI_Wtime();
}
result = read_entities(file_name);
if (CUBIT_SUCCESS != result) {
PRINT_ERROR("Reading file %s failed.\n", file_name);
return CUBIT_FAILURE;
} else if (CGM_read_parallel_debug) {
tEnd = MPI_Wtime();
PRINT_INFO("Read time in proc %d is %f.\n", m_rank, tEnd - tStart);
PRINT_INFO("Read done.\n");
}
break;
//==================
case PA_BALANCE:
if (CGM_read_parallel_debug)
std::cout << "Balancing entities." << std::endl;
if (m_bal_method == ROUND_ROBIN)
result = balance_round_robin();
if (CUBIT_SUCCESS != result)
return result;
if (CGM_read_parallel_debug)
PRINT_INFO("Balancing entities done.\n");
break;
//==================
case PA_DELETE_NONLOCAL:
if (CGM_read_parallel_debug) {
PRINT_INFO("Deleting nonlocal entities.\n");
tStart = MPI_Wtime();
}
result = delete_nonlocal_entities(reader_rank, partition_tag_name,
partition_tag_vals);
if (CUBIT_SUCCESS != result) {
PRINT_ERROR("Delete failed.\n");
return CUBIT_FAILURE;
} else if (CGM_read_parallel_debug) {
tEnd = MPI_Wtime();
PRINT_INFO("Delete done.\n");
PRINT_INFO("Delete time in proc %d is %f.\n", m_rank, tEnd - tStart);
}
break;
//==================
case PA_BROADCAST:
// do the actual broadcast; if single-processor, ignore error
if (m_proc_size > 1) {
if (CGM_read_parallel_debug) {
PRINT_INFO("Broadcasting Body entities.\n");
tStart = MPI_Wtime();
}
result = m_pcomm->broadcast_entities(reader_rank,
m_pcomm->partition_body_list());
if (CUBIT_SUCCESS != result) {
PRINT_ERROR("Broadcasting Body entities failed.\n");
return CUBIT_FAILURE;
} else if (CGM_read_parallel_debug) {
tEnd = MPI_Wtime();
PRINT_INFO("Bcast bodies done.\n");
PRINT_INFO("Broadcast bodies time in proc %d is %f.\n", m_proc_size,
tEnd - tStart);
}
if (!check_partition_info()) {
PRINT_ERROR("Check partition info failed.\n");
return CUBIT_FAILURE;
}
}
break;
//==================
case PA_SCATTER:
// do the actual scatter
if (m_proc_size > 1) {
if (CGM_read_parallel_debug) {
PRINT_INFO("Scattering body entities.\n");
tStart = MPI_Wtime();
}
result = m_pcomm->scatter_entities(reader_rank,
m_pcomm->partition_body_list());
if (CUBIT_SUCCESS != result) {
PRINT_ERROR("Scattering body entities failed.\n");
return CUBIT_FAILURE;
} else if (CGM_read_parallel_debug) {
tEnd = MPI_Wtime();
PRINT_INFO("Scatter bodies done.\n");
PRINT_INFO("Scatter bodies time in proc %d is %f.\n", m_proc_size,
tEnd - tStart);
}
if (!check_partition_info()) {
PRINT_ERROR("Check partition info failed.\n");
return CUBIT_FAILURE;
}
}
if (CGM_read_parallel_debug)
PRINT_INFO("Scatter done.\n");
break;
//==================
default:
return CUBIT_FAILURE;
}
}
return CUBIT_SUCCESS;
}
CubitStatus CGMReadParallel::read_entities(const char* file_name) {
// check file type
CubitString file_type;
if (strstr(file_name, ".stp"))
file_type = "STEP";
else if (strstr(file_name, ".igs"))
file_type = "IGES";
else if (strstr(file_name, ".occ") || strstr(file_name, ".OCC")
|| strstr(file_name, ".brep") || strstr(file_name, ".BREP"))
file_type = "OCC";
else {
PRINT_ERROR("File type not known for file %s; skipping.\n", file_name);
return CUBIT_FAILURE;
}
// import solid model
CubitStatus result = CubitCompat_import_solid_model(file_name,
file_type.c_str());
if (CUBIT_SUCCESS != result) {
PRINT_ERROR("Reading file %s failed.\n", file_name);
return CUBIT_FAILURE;
}
// get body entities
DLIList<RefEntity*>& body_entity_list = m_pcomm->partition_body_list();
body_entity_list.clean_out();
result = m_gqt->ref_entity_list("body", body_entity_list, CUBIT_FALSE);
if (CUBIT_SUCCESS != result) {
PRINT_ERROR("Getting Body entities failed.\n");
return result;
}
return result;
}
CubitStatus CGMReadParallel::balance_round_robin() {
// get bodies
int i, j, k;<--- The scope of the variable 'j' can be reduced. [+]The scope of the variable 'j' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level. <--- The scope of the variable 'k' can be reduced. [+]The scope of the variable 'k' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
DLIList<RefEntity*>& body_entity_list = m_pcomm->partition_body_list();
int n_proc = m_proc_size;
double* loads = new double[n_proc]; // estimated loads for each processor
double* ve_loads = new double[n_proc]; // estimated loads for each processor
for (i = 0; i < n_proc; i++) {
loads[i] = 0.0;
ve_loads[i] = 0.0;
}
if (m_bal_method == ROUND_ROBIN) { // round-robin case
int n_entity = body_entity_list.size();
int n_entity_proc = n_entity / n_proc; // # of entities per processor
int i_entity_proc = n_entity_proc; // entity index limit for each processor
int proc = 0;
RefEntity* entity;
// assign processors to bodies
body_entity_list.reset();
for (i = 0; i < n_entity; i++) {
if (i == i_entity_proc) {
proc++;
if (proc < n_proc)
i_entity_proc += n_entity_proc;
else {
proc %= n_proc;
i_entity_proc++;
}
}
// assign to bodies
entity = body_entity_list.get_and_step();
DLIList<int> shared_procs;
shared_procs.append(proc);
TDParallel *td_par = (TDParallel *) entity->get_TD(
&TDParallel::is_parallel);
if (td_par == NULL)
td_par = new TDParallel(entity, NULL, &shared_procs);
loads[proc] += entity->measure();
// assign to volumes, it should be removed in future
DLIList<RefVolume*> volumes;
(dynamic_cast<TopologyEntity*>(entity))->ref_volumes(volumes);
int n_vol = volumes.size();
volumes.reset();
for (j = 0; j < n_vol; j++) {
RefEntity *vol = volumes.get_and_step();
td_par = (TDParallel *) vol->get_TD(&TDParallel::is_parallel);
if (td_par == NULL)
td_par = new TDParallel(vol, NULL, &shared_procs);
}
// add local surface load
DLIList<RefFace*> faces;
(dynamic_cast<TopologyEntity*>(entity))->ref_faces(faces);
int n_face = faces.size();
faces.reset();
for (j = 0; j < n_face; j++) {
RefFace* face = faces.get_and_step();
TopologyEntity *te = CAST_TO(face, TopologyEntity);
if (te->bridge_manager()->number_of_bridges() < 2) {
loads[proc] = loads[proc] + face->measure();
}
}
}
// Get all child entities
DLIList<RefEntity*> child_list;
RefEntity::get_all_child_ref_entities(body_entity_list, child_list);
int n_child = child_list.size();
// assign processors to interface entities
child_list.reset();
for (i = 0; i < n_child; i++) {
entity = child_list.get_and_step();
TopologyEntity *te = CAST_TO(entity, TopologyEntity);
if (te->bridge_manager()->number_of_bridges() > 1) {
DLIList<Body*> parent_bodies;
DLIList<int> shared_procs;
(dynamic_cast<TopologyEntity*>(entity))->bodies(parent_bodies);
int n_parent = parent_bodies.size();
for (j = 0; j < n_parent; j++) {
RefEntity *parent_vol = CAST_TO(parent_bodies.get_and_step(),
RefEntity);
TDParallel *parent_td = (TDParallel *) parent_vol->get_TD(
&TDParallel::is_parallel);
if (parent_td == NULL) {
PRINT_ERROR("parent Volume has to be partitioned.");
return CUBIT_FAILURE;
}
shared_procs.append_unique(parent_td->get_charge_proc());
}
if (shared_procs.size() > 1) { // if it is interface
TDParallel *td_par = (TDParallel *) entity->get_TD(
&TDParallel::is_parallel);
if (td_par == NULL) {
int merge_id = TDUniqueId::get_unique_id(entity);
if (entity->entity_type_info() == typeid(RefFace)) { // face
if (shared_procs.size() != 2) {
PRINT_ERROR(
"Error: # of shared processors of interface surface should be 2.");
return CUBIT_FAILURE;
}
// balance interface surface loads
if (loads[shared_procs[0]] > loads[shared_procs[1]]) {
shared_procs.reverse();
}
loads[shared_procs[0]] = loads[shared_procs[0]]
+ entity->measure();
td_par = new TDParallel(entity, NULL, &shared_procs, NULL,
merge_id, 1);
} else if (entity->entity_type_info() == typeid(RefEdge)
|| entity->entity_type_info() == typeid(RefVertex)) {
// balance interface surface loads
int min_p = shared_procs[0];
int n_shared_proc = shared_procs.size();
for (int i1 = 1; i1 < n_shared_proc; i1++) {
if (ve_loads[shared_procs[i1]] < ve_loads[min_p]) {
min_p = shared_procs[i1];
}
}
ve_loads[min_p] = ve_loads[min_p] + entity->measure();
shared_procs.remove(min_p);
shared_procs.insert_first(min_p);
// add ghost geometries to shared processors for edge
if (entity->entity_type_info() == typeid(RefEdge)) {
parent_bodies.reset();
for (j = 0; j < n_parent; j++) {
RefEntity *parent_vol = CAST_TO(parent_bodies.get_and_step(),
RefEntity);
TDParallel *parent_td = (TDParallel *) parent_vol->get_TD(
&TDParallel::is_parallel);
for (k = 0; k < n_shared_proc; k++) {
parent_td->add_ghost_proc(shared_procs[k]);
}
}
}
td_par = new TDParallel(entity, NULL, &shared_procs, NULL,
merge_id, 1);
}
}
}
}
}
} else if (m_bal_method == PARTITION_DYNAMIC) {
}
return CUBIT_SUCCESS;
}
CubitStatus CGMReadParallel::delete_nonlocal_entities(int reader,
std::string &ptag_name, std::vector<int> &ptag_vals) {
// find bodies deleted
int i;
DLIList<RefEntity*>& body_entity_list = m_pcomm->partition_body_list();
DLIList<RefEntity*> partition_list, delete_body_list;
int nEntity = body_entity_list.size();
body_entity_list.reset();
for (i = 0; i < nEntity; i++) {
RefEntity* entity = body_entity_list.get_and_step();
TDParallel *td_par = (TDParallel *) entity->get_TD(
&TDParallel::is_parallel);
if (td_par == NULL) {
PRINT_ERROR("Partitioned Volume should have TDParallel data.");
return CUBIT_FAILURE;
}
if (td_par->get_charge_proc() != m_rank) { // candidate to be deleted
// check child surfaces if surface partitioned
DLIList<RefFace*> face_list;
(dynamic_cast<TopologyEntity*>(entity))->ref_faces(face_list);
bool b_partitioned_surf = false;
int n_face = face_list.size();
face_list.reset();
for (int j = 0; j < n_face; j++) {
RefEntity* face = face_list.get_and_step();
TDParallel *td_par_face = (TDParallel *) face->get_TD(
&TDParallel::is_parallel);
if (td_par_face != NULL) { // if surface is partitioned
DLIList<int>* shared_procs = td_par_face->get_shared_proc_list();
int n_shared = shared_procs->size();
shared_procs->reset();
for (int k = 0; k < n_shared; k++) {
if (shared_procs->get_and_step() == (int) m_rank) {
b_partitioned_surf = true;
break;
}
}
}
}
if (b_partitioned_surf)
partition_list.append(entity);
else
delete_body_list.append(entity);
} else
partition_list.append(entity);
}
// print info
char pre_body[100];<--- The scope of the variable 'pre_body' can be reduced. [+]The scope of the variable 'pre_body' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
DLIList<CubitEntity*> tmp_body_list;
if (CGM_read_parallel_debug) {
if ((int) m_rank != reader) {
CAST_LIST_TO_PARENT(delete_body_list, tmp_body_list);
sprintf(pre_body, "Will delete %d Bodies: ", tmp_body_list.size());
CubitUtil::list_entity_ids(pre_body, tmp_body_list);
}
std::cout << "Partitioned Body list size after delete: "
<< partition_list.size() << std::endl;
}
// delete bodies
nEntity = delete_body_list.size();
delete_body_list.reset();
for (i = 0; i < nEntity; i++) {
GeometryQueryTool::instance()->delete_RefEntity(
delete_body_list.get_and_step());
}
// update Body list in ParallelComm
body_entity_list.clean_out();
body_entity_list += partition_list;
return CUBIT_SUCCESS;
}
CubitStatus CGMReadParallel::check_partition_info() {
int i;
DLIList<RefEntity*>& body_entity_list = m_pcomm->partition_body_list();
int nEntity = body_entity_list.size();
body_entity_list.reset();
for (i = 0; i < nEntity; i++) {
RefEntity* entity = body_entity_list.get_and_step();
TDParallel *td_par = (TDParallel *) entity->get_TD(
&TDParallel::is_parallel);
if (td_par == NULL) { // if body is not partitioned
DLIList<RefEntity*> volumes;
entity->get_child_ref_entities(volumes);
// check if the first Volume is partitioned here, should be removed in future
volumes.reset();
RefEntity *vol = volumes.get();
if (vol == NULL || vol->entity_type_info() != typeid(RefVolume)) {
PRINT_ERROR("Partitioned Body should have at least one Volume.");
return CUBIT_FAILURE;
}
td_par = (TDParallel *) vol->get_TD(&TDParallel::is_parallel);
if (td_par == NULL) {
PRINT_ERROR("Partitioned Volume should have TDParallel data.");
return CUBIT_FAILURE;
}
DLIList<int> s_procs;
s_procs.append(td_par->get_charge_proc());
td_par = new TDParallel(entity, NULL, &s_procs);
}
}
return CUBIT_SUCCESS;
}
|