flush printf buffer before call system()

21 views
Skip to first unread message

Eric Fisher

unread,
Dec 14, 2009, 3:53:38 AM12/14/09
to ctuning-d...@googlegroups.com
Hi,

Recently I realized that the screen output of ccc is not sequential.
So I have to put "fflush(stdout);" before each call of system() in the
source code to fix it..

Best regards,
Mingjie

Grigori Fursin

unread,
Dec 14, 2009, 9:56:29 AM12/14/09
to ctuning-d...@googlegroups.com
Thanks, Mingjie.
Did you commit the changes?..
Don't forget to update the build number (in ccc-build.cfg)
and put a note about your update in README.txt ...
Thanks,
Grigori
> --
>
> You received this message because you are subscribed to the Google Groups "ctuning-
> discussions" group.
> To post to this group, send email to ctuning-d...@googlegroups.com.
> To unsubscribe from this group, send email to ctuning-
> discussions...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ctuning-
> discussions?hl=en.


Eric Fisher

unread,
Dec 14, 2009, 10:16:47 PM12/14/09
to ctuning-d...@googlegroups.com
Hi Grigori,

I'd like to put the patch here.

Best regards,
Mingjie

2009-12-15 Mingjie Xing <joefo...@gmail.com>
* src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c:
src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c:
src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c:
src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c:
add fflush(stdout) before system()

Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
(working copy)
@@ -144,12 +144,14 @@ int main(int argc, char* argv[])

printf("Compiling with compiler %s and option %s\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(stdout);
system(str2);

printf(sep2 "\n");
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(stdout);
system(str2);

istep++;
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c
(working copy)
@@ -143,12 +143,14 @@ int main(int argc, char* argv[])

printf("Compiling with compiler %s and option %s\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(stdout);
system(str2);

printf(sep2 "\n");
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(stdout);
system(str2);

istep++;
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c
(working copy)
@@ -146,12 +146,14 @@ int main(int argc, char* argv[])

printf("Compiling with compiler %s and option %s\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(stdout);
system(str2);

printf(sep2 "\n");
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(stdout);
system(str2);

istep++;
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c
(working copy)
@@ -160,9 +160,11 @@ int main(int argc, char* argv[])
if (change>=0) printf("Removing option %s ...\n\n",
&opts[iopts[change]]);
}

+ fflush(stdout);
system(_del " " _fout);
printf("Compiling with compiler %s and option %s\n\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(stdout);
system(str2);

if (fileExist(_fobjmd5)==1)
@@ -206,6 +208,7 @@ int main(int argc, char* argv[])
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(stdout);
system(str2);

//Read time



2009/12/14 Grigori Fursin <gfu...@gmail.com>:
> You received this message because you are subscribed to the Google Groups "ctuning-discussions" group.
> To post to this group, send email to ctuning-d...@googlegroups.com.
> To unsubscribe from this group, send email to ctuning-discuss...@googlegroups.com.

Basile STARYNKEVITCH

unread,
Dec 15, 2009, 1:16:27 AM12/15/09
to ctuning-d...@googlegroups.com
Eric Fisher wrote:
> Hi Grigori,
>
> I'd like to put the patch here.


> Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
> ===================================================================
> --- src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
> (revision 89)
> +++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
> (working copy)
> @@ -144,12 +144,14 @@ int main(int argc, char* argv[])
>
> printf("Compiling with compiler %s and option %s\n", comp_name,
> trim(str_opt));
> sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
> + fflush(stdout);

I would also add
fflush (stderr);

and you could even call
fflush ((FILE*)0);
because according to the man page:
If the stream argument is NULL, fflush() flushes all open output
streams.
But I don't know how portable is it to fflush the null stream.

Regards.


--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

Eric Fisher

unread,
Dec 15, 2009, 1:28:26 AM12/15/09
to ctuning-d...@googlegroups.com
2009/12/15 Basile STARYNKEVITCH <bas...@starynkevitch.net>:
> I would also add
>        fflush (stderr);
>
> and you could even call
>        fflush ((FILE*)0);
> because according to the man page:
>        If  the  stream  argument  is  NULL,  fflush()  flushes all open output
>        streams.
> But I don't know how portable is it to fflush the null stream.
>
> Regards.

Yes, sure. People in ##c channel of freenode IRC also told me that
fflush(NULL) is better.

Thanks,
Mingjie

Grigori Fursin

unread,
Dec 15, 2009, 10:20:17 AM12/15/09
to ctuning-d...@googlegroups.com
Sure. Please put fflush(NULL) to the places you identified.
I don't remember if you are registered as a developer on CCC Sourceforge?
If not, please send me your ID and I will give you write access to the SVN ...
Thanks,
Grigori


> -----Original Message-----
> From: ctuning-d...@googlegroups.com [mailto:ctuning-d...@googlegroups.com] On
> Behalf Of Eric Fisher

Eric Fisher

unread,
Dec 15, 2009, 10:39:17 PM12/15/09
to ctuning-d...@googlegroups.com
Hi Grigori,

It's great. Thanks. I haven't registered on CCC Sourceforge. If it is
possible I would like to use "xmj" as my ID. Here is the modified
patch.

Best regards,
Mingjie

Index: ccc-build.cfg
===================================================================
--- ccc-build.cfg (revision 89)
+++ ccc-build.cfg (working copy)
@@ -1 +1 @@
-1011
+1012
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c
(working copy)
@@ -144,12 +144,14 @@ int main(int argc, char* argv[])

printf("Compiling with compiler %s and option %s\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(NULL);
system(str2);

printf(sep2 "\n");
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(NULL);
system(str2);

istep++;
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c
(working copy)
@@ -143,12 +143,14 @@ int main(int argc, char* argv[])

printf("Compiling with compiler %s and option %s\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(NULL);
system(str2);

printf(sep2 "\n");
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(NULL);
system(str2);

istep++;
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c
(working copy)
@@ -146,12 +146,14 @@ int main(int argc, char* argv[])

printf("Compiling with compiler %s and option %s\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(NULL);
system(str2);

printf(sep2 "\n");
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(NULL);
system(str2);

istep++;
Index: src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c
===================================================================
--- src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c
(revision 89)
+++ src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c
(working copy)
@@ -160,9 +160,11 @@ int main(int argc, char* argv[])
if (change>=0) printf("Removing option %s ...\n\n",
&opts[iopts[change]]);
}

+ fflush(NULL);
system(_del " " _fout);
printf("Compiling with compiler %s and option %s\n\n", comp_name,
trim(str_opt));
sprintf(str2, _ccc_comp " %s \"%s\"", comp_name, trim(str_opt));
+ fflush(NULL);
system(str2);

if (fileExist(_fobjmd5)==1)
@@ -206,6 +208,7 @@ int main(int argc, char* argv[])
printf("Running program with dataset %u, first time=%u\n", mds, first);

sprintf(str2, _ccc_run " %u %u", mds, first);
+ fflush(NULL);
system(str2);

//Read time
Index: README.txt
===================================================================
--- README.txt (revision 89)
+++ README.txt (working copy)
@@ -116,6 +116,12 @@ Collective Optimization Database Copyrig
****************************************************************
CCC Version history:

+ Build 1012: *
src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-fixed/ccc-run-glob-flags-rnd-fixed.c:
+
src-plat-dep/plugins/compilation/ccc-run-glob-flags-rnd-uniform/ccc-run-glob-flags-rnd-uniform.c:
+
src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-by-one/ccc-run-glob-flags-one-by-one.c:
+
src-plat-dep/plugins/compilation/ccc-run-glob-flags-one-off-rnd/ccc-run-glob-flags-one-off-rnd.c:
+ Put fflush(NULL) before system();
+
Build 1011: * Time measurement
mechanism changed. Now we are using /usr/bin/time program.

Build 1010: * Fixed bug in ccc-comp wrapper script that
would not parse

105,1 Bot


2009/12/15 Grigori Fursin <gfu...@gmail.com>:
> You received this message because you are subscribed to the Google Groups "ctuning-discussions" group.
> To post to this group, send email to ctuning-d...@googlegroups.com.
> To unsubscribe from this group, send email to ctuning-discuss...@googlegroups.com.

Yuri Kashnikoff

unread,
Dec 16, 2009, 4:00:28 AM12/16/09
to ctuning-d...@googlegroups.com
Hi Mingjie,

> It's great. Thanks. I haven't registered on CCC Sourceforge. If it is
> possible I would like to use "xmj" as my ID.  Here is the modified
> patch.

Have you registered your "xmj" account on Sourceforge?

Thanks!

Eric Fisher

unread,
Dec 16, 2009, 4:07:43 AM12/16/09
to ctuning-d...@googlegroups.com
2009/12/16 Yuri Kashnikoff <yuri.ka...@gmail.com>:
Sorry, Yuri. I misunderstood. I have a registered account 'ericfisher'
on Sourceforge. Is it OK?

Thanks
Mingjie

Yuri Kashnikoff

unread,
Dec 16, 2009, 4:36:08 AM12/16/09
to ctuning-d...@googlegroups.com
> Hi Mingjie,

> Sorry, Yuri. I misunderstood. I have a registered account 'ericfisher'
> on Sourceforge. Is it OK?

Sure!

Grigori, could you add 'ericfisher' account to the CCC committers, so
he could commit the patch?

Thanks!

Grigori Fursin

unread,
Dec 16, 2009, 9:34:37 AM12/16/09
to ctuning-d...@googlegroups.com
Done!
Grigori

> -----Original Message-----
> From: ctuning-d...@googlegroups.com [mailto:ctuning-d...@googlegroups.com] On
> Behalf Of Yuri Kashnikoff
> Sent: Wednesday, December 16, 2009 4:36 AM
> To: ctuning-d...@googlegroups.com
> Subject: Re: flush printf buffer before call system()
>
Reply all
Reply to author
Forward
0 new messages