Skip to content

Commit df41274

Browse files
authored
Merge pull request #2169 from aaronfinke/suppress_printf_to_mpimaster
added MPI_MASTER to selected printf statements
2 parents eec1ac6 + c0db3fe commit df41274

File tree

4 files changed

+85
-51
lines changed

4 files changed

+85
-51
lines changed

mcstas-comps/samples/NCrystal_sample.comp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ INITIALIZE
178178
NCMCERR("Inconsistent NCrystal library versions detected - this should normally not be possible!");
179179
}
180180
ncsample_reported_version = ncrystal_version();
181-
printf( "NCrystal: McStas sample component(s) are using version %s of the NCrystal library.\n",ncrystal_version_str());
181+
MPI_MASTER(
182+
printf( "NCrystal: McStas sample component(s) are using version %s of the NCrystal library.\n",ncrystal_version_str());
183+
);
182184
}
183185

184186
//The following conversion factors might look slightly odd. They reflect the

mcstas-comps/samples/Single_crystal.comp

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,9 @@ struct hkl_data
604604
/* when lengths a,b,c + angles are given (instead of vectors a,b,c) */
605605
if (info->m_aa && info->m_bb && info->m_cc)
606606
{
607-
printf("Mode: lengths and angles\n");
607+
MPI_MASTER(
608+
printf("Mode: lengths and angles\n");
609+
);
608610
double as,bs,cs;
609611
if (info->m_a) as = info->m_a;
610612
else as = sqrt(info->m_ax*info->m_ax+info->m_ay*info->m_ay+info->m_az*info->m_az);
@@ -622,21 +624,27 @@ struct hkl_data
622624
/sin(info->m_cc*DEG2RAD);
623625
info->m_cx = sqrt(cs*cs - info->m_cz*info->m_cz - info->m_cy*info->m_cy);
624626

625-
printf("Single_crystal: %s structure a=%g b=%g c=%g aa=%g bb=%g cc=%g ",
627+
MPI_MASTER(
628+
printf("Single_crystal: %s structure a=%g b=%g c=%g aa=%g bb=%g cc=%g ",
626629
(flag ? "INC" : SC_file), as, bs, cs, info->m_aa, info->m_bb, info->m_cc);
630+
);
627631
} else {
628632
if (!info->recip) {
629-
printf("Mode: Direct mode lattice\n");
630-
printf("Single_crystal: %s structure a=[%g,%g,%g] b=[%g,%g,%g] c=[%g,%g,%g] ",
631-
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
632-
info->m_bx ,info->m_by ,info->m_bz,
633-
info->m_cx ,info->m_cy ,info->m_cz);
633+
MPI_MASTER(
634+
printf("Mode: Direct mode lattice\n");
635+
printf("Single_crystal: %s structure a=[%g,%g,%g] b=[%g,%g,%g] c=[%g,%g,%g] ",
636+
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
637+
info->m_bx ,info->m_by ,info->m_bz,
638+
info->m_cx ,info->m_cy ,info->m_cz);
639+
);
634640
} else {
635-
printf("Mode: Reciprocal mode lattice\n");
636-
printf("Single_crystal: %s structure a*=[%g,%g,%g] b*=[%g,%g,%g] c*=[%g,%g,%g] ",
637-
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
638-
info->m_bx ,info->m_by ,info->m_bz,
639-
info->m_cx ,info->m_cy ,info->m_cz);
641+
MPI_MASTER(
642+
printf("Mode: Reciprocal mode lattice\n");
643+
printf("Single_crystal: %s structure a*=[%g,%g,%g] b*=[%g,%g,%g] c*=[%g,%g,%g] ",
644+
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
645+
info->m_bx ,info->m_by ,info->m_bz,
646+
info->m_cx ,info->m_cy ,info->m_cz);
647+
);
640648
}
641649
}
642650
/* Compute reciprocal or direct lattice vectors. */
@@ -645,7 +653,9 @@ struct hkl_data
645653
info->m_bx, info->m_by, info->m_bz,
646654
info->m_cx, info->m_cy, info->m_cz);
647655
info->V0 = fabs(scalar_prod(info->m_ax, info->m_ay, info->m_az, tmp_x, tmp_y, tmp_z));
648-
printf("V0=%g\n", info->V0);
656+
MPI_MASTER(
657+
printf("V0=%g\n", info->V0);
658+
);
649659

650660
info->asx = 2*PI/info->V0*tmp_x;
651661
info->asy = 2*PI/info->V0*tmp_y;
@@ -673,7 +683,9 @@ struct hkl_data
673683
info->bsx/(2*PI), info->bsy/(2*PI), info->bsz/(2*PI),
674684
info->csx/(2*PI), info->csy/(2*PI), info->csz/(2*PI));
675685
info->V0 = 1/fabs(scalar_prod(info->asx/(2*PI), info->asy/(2*PI), info->asz/(2*PI), tmp_x, tmp_y, tmp_z));
676-
printf("V0=%g\n", info->V0);
686+
MPI_MASTER(
687+
printf("V0=%g\n", info->V0);
688+
);
677689

678690
/*compute the direct cell parameters, ofr completeness*/
679691
info->m_ax = tmp_x*info->V0;
@@ -1168,12 +1180,17 @@ INITIALIZE
11681180
if (hkl_info.sigma_a<0) hkl_info.sigma_a=0;
11691181
if (hkl_info.sigma_i<0) hkl_info.sigma_i=0;
11701182

1171-
if (hkl_info.count)
1172-
printf("Single_crystal: %s: Read %d reflections from file '%s'\n",
1173-
NAME_CURRENT_COMP, hkl_info.count, reflections);
1174-
else printf("Single_crystal: %s: Using incoherent elastic scattering only sigma=%g.\n",
1183+
if (hkl_info.count) {
1184+
MPI_MASTER(
1185+
printf("Single_crystal: %s: Read %d reflections from file '%s'\n",
1186+
NAME_CURRENT_COMP, hkl_info.count, reflections);
1187+
);
1188+
} else {
1189+
MPI_MASTER(
1190+
printf("Single_crystal: %s: Using incoherent elastic scattering only sigma=%g.\n",
11751191
NAME_CURRENT_COMP, hkl_info.sigma_i);
1176-
1192+
);
1193+
}
11771194
/*this should not be in hkl_info*/
11781195
hkl_info.shape=-1; /* -1:no shape, 0:cyl, 1:box, 2:sphere, 3:any-shape */
11791196
if (geometry && strlen(geometry) && strcmp(geometry, "NULL") && strcmp(geometry, "0")) {
@@ -1195,10 +1212,11 @@ INITIALIZE
11951212
exit(fprintf(stderr,"Single_crystal: %s: sample has invalid dimensions.\n"
11961213
"ERROR Please check parameter values (xwidth, yheight, zdepth, radius).\n", NAME_CURRENT_COMP));
11971214

1198-
printf("Single_crystal: %s: Vc=%g [Angs] sigma_abs=%g [barn] sigma_inc=%g [barn] reflections=%s\n",
1215+
MPI_MASTER(
1216+
printf("Single_crystal: %s: Vc=%g [Angs] sigma_abs=%g [barn] sigma_inc=%g [barn] reflections=%s\n",
11991217
NAME_CURRENT_COMP, hkl_info.V0, hkl_info.sigma_a, hkl_info.sigma_i,
12001218
reflections && strlen(reflections) ? reflections : "NULL");
1201-
1219+
);
12021220
if (powder && PG)
12031221
exit(fprintf(stderr,"Single_crystal: %s: powder and PG modes can not be used together!\n"
12041222
"ERROR Please use EITHER powder or PG mode.\n", NAME_CURRENT_COMP));
@@ -1218,16 +1236,16 @@ INITIALIZE
12181236
if (order==0 && extra_order) {
12191237
fprintf(stderr, "Single_crystal: %s: extra_order used while order=0, then this option has no effect\n", NAME_CURRENT_COMP);
12201238
}
1221-
1222-
printf("Direct space lattice orientation:\n");
1223-
printf(" a = [%g %g %g]\n", hkl_info.m_ax, hkl_info.m_ay, hkl_info.m_az);
1224-
printf(" b = [%g %g %g]\n", hkl_info.m_bx, hkl_info.m_by, hkl_info.m_bz);
1225-
printf(" c = [%g %g %g]\n", hkl_info.m_cx, hkl_info.m_cy, hkl_info.m_cz);
1226-
printf("Reciprocal space lattice orientation:\n");
1227-
printf(" a* = [%g %g %g]\n", hkl_info.asx, hkl_info.asy, hkl_info.asz);
1228-
printf(" b* = [%g %g %g]\n", hkl_info.bsx, hkl_info.bsy, hkl_info.bsz);
1229-
printf(" c* = [%g %g %g]\n", hkl_info.csx, hkl_info.csy, hkl_info.csz);
1230-
1239+
MPI_MASTER(
1240+
printf("Direct space lattice orientation:\n");
1241+
printf(" a = [%g %g %g]\n", hkl_info.m_ax, hkl_info.m_ay, hkl_info.m_az);
1242+
printf(" b = [%g %g %g]\n", hkl_info.m_bx, hkl_info.m_by, hkl_info.m_bz);
1243+
printf(" c = [%g %g %g]\n", hkl_info.m_cx, hkl_info.m_cy, hkl_info.m_cz);
1244+
printf("Reciprocal space lattice orientation:\n");
1245+
printf(" a* = [%g %g %g]\n", hkl_info.asx, hkl_info.asy, hkl_info.asz);
1246+
printf(" b* = [%g %g %g]\n", hkl_info.bsx, hkl_info.bsy, hkl_info.bsz);
1247+
printf(" c* = [%g %g %g]\n", hkl_info.csx, hkl_info.csy, hkl_info.csz);
1248+
);
12311249
%}
12321250

12331251
TRACE
@@ -1459,7 +1477,9 @@ TRACE
14591477
&coh_refl, &coh_xsect, oclContext_SX,
14601478
d_L, d_T, d_tau_count, d_coh_refl, d_coh_xsect);
14611479
if (tau_count != 0)
1480+
MPI_MASTER(
14621481
printf("\nGPU tau_count:%i\n",tau_count);
1482+
);
14631483
}
14641484
else
14651485
#endif

mcstas-comps/union/NCrystal_process.comp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ INITIALIZE
284284
NCMCERR("Inconsistent NCrystal library versions detected - this should normally not be possible!");
285285
}
286286
ncsample_reported_version_union = ncrystal_version();
287-
printf( "NCrystal: McStas Union process component(s) are using version %s of the NCrystal library.\n", ncrystal_version_str());
287+
MPI_MASTER(
288+
printf( "NCrystal: McStas Union process component(s) are using version %s of the NCrystal library.\n", ncrystal_version_str());
289+
);
288290
}
289291

290292
//The following conversion factors might look slightly odd. They reflect the

mcstas-comps/union/Powder_process.comp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ SHARE
161161
int list_count=0;
162162

163163
if (!SC_file || !strlen(SC_file) || !strcmp(SC_file, "NULL")) {
164-
printf("PowderN: %s: Using incoherent elastic scattering only\n",info->compname);
164+
MPI_MASTER(
165+
printf("PowderN: %s: Using incoherent elastic scattering only\n",info->compname);
166+
);
165167
info->count = 0;
166168
return(0);
167169
}
@@ -225,17 +227,18 @@ SHARE
225227
"should be at least %d\n", info->compname, SC_file, 1));
226228
else size = sTable.rows;
227229
Table_Info(sTable);
228-
printf("PowderN: %s: Reading %d rows from %s\n",
229-
info->compname, size, SC_file);
230-
231-
if (info->column_order[0] == 4 && info->flag_barns !=0)
232-
printf("PowderN: %s: Powder file probably of type Crystallographica/Fullprof (lau)\n"
233-
"WARNING: but F2 unit is set to barns=1 (barns). Intensity might be 100 times too high.\n",
234-
info->compname);
235-
if (info->column_order[0] == 17 && info->flag_barns == 0)
236-
printf("PowderN: %s: Powder file probably of type Lazy Pulver (laz)\n"
237-
"WARNING: but F2 unit is set to barns=0 (fm^2). Intensity might be 100 times too low.\n",
238-
info->compname);
230+
MPI_MASTER(
231+
printf("PowderN: %s: Reading %d rows from %s\n",
232+
info->compname, size, SC_file);
233+
if (info->column_order[0] == 4 && info->flag_barns !=0)
234+
printf("PowderN: %s: Powder file probably of type Crystallographica/Fullprof (lau)\n"
235+
"WARNING: but F2 unit is set to barns=1 (barns). Intensity might be 100 times too high.\n",
236+
info->compname);
237+
if (info->column_order[0] == 17 && info->flag_barns == 0)
238+
printf("PowderN: %s: Powder file probably of type Lazy Pulver (laz)\n"
239+
"WARNING: but F2 unit is set to barns=0 (fm^2). Intensity might be 100 times too low.\n",
240+
info->compname);
241+
);
239242
/* allocate line_data array */
240243
list = (struct line_data_union*)malloc(size*sizeof(struct line_data_union));
241244

@@ -282,8 +285,10 @@ SHARE
282285
w = (w>0 ? w : 0); /* this is q and d relative spreading */
283286
F2 = (F2 >= 0 ? F2 : 0);
284287
if (j == 0 || q == 0) {
285-
printf("PowderN: %s: line %i has invalid definition\n"
288+
MPI_MASTER(
289+
printf("PowderN: %s: line %i has invalid definition\n"
286290
" (mult=0 or q=0 or d=0)\n", info->compname, i);
291+
);
287292
continue;
288293
}
289294
list[list_count].j = j;
@@ -312,9 +317,11 @@ SHARE
312317
&& (mult_count == list[list_count-1].j
313318
|| ((list_count < size) && (i == size - 1)
314319
&& (mult_count == list[list_count].j))) ) {
315-
printf("PowderN: %s: Set multiplicity to 1 for lines [%i:%i]\n"
320+
MPI_MASTER(
321+
printf("PowderN: %s: Set multiplicity to 1 for lines [%i:%i]\n"
316322
" (d-spacing %g is duplicated %i times)\n",
317-
info->compname, list_count-mult_count, list_count-1, list[list_count-1].q, mult_count);
323+
info->compname, list_count-mult_count, list_count-1, list[list_count-1].q, mult_count);
324+
);
318325
for (index=list_count-mult_count; index<list_count; list[index++].j = 1);
319326
mult_count = 1;
320327
q_count = q;
@@ -332,9 +339,10 @@ SHARE
332339
/* sort the list with increasing q */
333340
qsort(list, list_count, sizeof(struct line_data_union), PN_list_compare_union);
334341

335-
printf("PowderN: %s: Read %i reflections from file '%s'\n",
342+
MPI_MASTER(
343+
printf("PowderN: %s: Read %i reflections from file '%s'\n",
336344
info->compname, list_count, SC_file);
337-
345+
);
338346
info->list = list;
339347
info->count = list_count;
340348

@@ -737,8 +745,10 @@ INITIALIZE
737745
line_info.my_a_v = packing_factor*line_info.sigma_a/line_info.V_0*2200*100; // Factor 100 to convert from barns to fm^2
738746
line_info.my_inc = packing_factor*line_info.sigma_i/line_info.V_0*100; // Factor 100 to convert from barns to fm^2
739747

740-
printf("PowderN: %s: Vc=%g [Angs] sigma_abs=%g [barn] sigma_inc=%g [barn] reflections=%s\n",
748+
MPI_MASTER(
749+
printf("PowderN: %s: Vc=%g [Angs] sigma_abs=%g [barn] sigma_inc=%g [barn] reflections=%s\n",
741750
NAME_CURRENT_COMP, line_info.V_0, line_info.sigma_a, line_info.sigma_i, reflections && strlen(reflections) ? reflections : "NULL");
751+
);
742752
}
743753

744754
//printf("INTIALIZE line_info.v = %f, line_info.v_min = %f, line_info.v_max = %f, line_info.neutron_passed = %f\n",line_info.v,line_info.v_min,line_info.v_max,line_info.neutron_passed);

0 commit comments

Comments
 (0)