Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Backslash Compiler option to overWRITE on console

Vishnu
Novice
997 Views

I am aware of this post.

But I currently use the gfortran -fbackslash compiler option to implement it (a progress indicator) as follows:

    WRITE(6,'(4(a))',ADVANCE="NO") "\b","\b","\b","\b"
    WRITE(6,'(I3,"%")',ADVANCE='NO') INT( (k*100)/REAL(n) )

I need my code to be compatible with gfortran as most of my collaborators use only that. Do you think ifort will add this (or equivalent) compiler option anytime? If not, can I make a request for this feature?

Thanks

0 Kudos
1 Solution
TimP
Honored Contributor III
997 Views

As there is already -assume bscc it seeme unlikely that ifort would add this alternate spelling.  You could submit a feature request.

View solution in original post

0 Kudos
14 Replies
TimP
Honored Contributor III
998 Views

As there is already -assume bscc it seeme unlikely that ifort would add this alternate spelling.  You could submit a feature request.

0 Kudos
Vishnu
Novice
997 Views

@Tim  When I say that I want that compiler option, I don't mean that it has to be exactly the same. Any option that will do the same thing is okay. Thanks for showing it to me.

I tried it, but it does not seem to work the same way `gfortran -fbackslash` does. The 'ADVANCE=NO' seems to be working, but nothing is printed. only the last, 100% appears. I had had this same problem with gfortran at first, but that was because the order of the two lines of code in my first post was the opposite of what it is now.

Any idea what might be going wrong?

0 Kudos
Kevin_D_Intel
Employee
997 Views

Can you provide us with a complete reproducer please?

It behaves for the simple program built below using the snippet provided earlier.

program u669986
integer :: k=1
integer :: n=2

WRITE(6,'((a))',ADVANCE='NO') "Percent =nnnn"
WRITE(6,'(4(a))',ADVANCE='NO') "\b","\b","\b","\b"
WRITE(6,'(I3,"%")',ADVANCE='NO') INT( (k*100)/REAL(n) )
WRITE(6,*)
WRITE(6,'((a))') "Done"

end
$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 16.0.3.210 Build 20160415
Copyright (C) 1985-2016 Intel Corporation.  All rights reserved.

$ ifort u669986.f90
$ ./a.out
Percent =nnnn\b\b\b\b 50%
Done

$ ifort -assume bscc u669986.f90
$ ./a.out
Percent = 50%
Done

$ gfortran u669986.f90 -o g.out
$ ./g.out
Percent =nnnn\b\b\b\b 50%
Done

$ gfortran -fbackslash u669986.f90 -o g.out
$ ./g.out
Percent = 50%
Done

 

0 Kudos
Vishnu
Novice
997 Views

This roughly simulates what I want:

PROGRAM test_bscc
INTEGER :: k, n=10

DO k =1, n    

    WRITE(6,'(4(A))',ADVANCE="NO") "\b","\b","\b","\b"
    CALL SLEEP(1)
    WRITE(6,'(I3,"%")',ADVANCE="NO") INT( (k*100)/REAL(n) )

END  DO

WRITE(6,'(" ")')

END PROGRAM

Running this with `gfortran -fbackslash` gives an output to the terminal that is constantly changing (from 10% to 100%). `ifort -assume bscc` on the other hand, just provides an output of 100% at the end of the program.

0 Kudos
Kevin_D_Intel
Employee
997 Views

The -assume nobuffered_stdout provides control over this and is the default but it seems its not working. Let me investigate further.

0 Kudos
jimdempseyatthecove
Honored Contributor III
997 Views

Try inserting FLUSH(6) at line 9

Jim Dempsey

0 Kudos
Vishnu
Novice
997 Views

With FLUSH(6) at line 9, I get:

$ ifort -assume bscc test_bscc.f90
$ ./a.out 
  5% 10% 15% 20% 25% 30% 35% 40% 45% 50% 55% 60% 65% 70% 75% 80% 85% 90% 95%100%

So then I tried putting FLUSH(6) after both lines 8 as well as 6. Doing that produces the desired output of a percentage marker that changes as required. Also, with the two FLUSHes,`gfortran -fbackslash` still produces output as before. Thanks a lot Jim!

Is it by design that it does not flush by default? As Kevin pointed out, isn't the default behaviour to not buffer stdout output?

0 Kudos
Kevin_D_Intel
Employee
997 Views

The behavior relates to non-advancing I/O which does not work with ifort (see reply # 4) in this earlier discussion, https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/277417. There is an alternative at that earlier thread that does work with ifort.

The FLUSH after lines 6 & 8 does not seem to work for me, but glad you found a solution.

While Development may say “no”, I submitted a (low) feature request to support non-buffered non-advancing I/O; hopefully no harm in asking.

(Internal tracking id: DPD200412750)

0 Kudos
jimdempseyatthecove
Honored Contributor III
997 Views

>>So then I tried putting FLUSH(6) after both lines 8 as well as 6. Doing that produces the desired output of a percentage marker that changes as required. Also, with the two FLUSHes,`gfortran -fbackslash` still produces output as before. Thanks a lot Jim!

Glad to be of help.

>>Is it by design that it does not flush by default?

The design is to buffer the output inside the application. Then at appropriate times, perform the actual I/O. While any impact on performance might not be an issue on a small (single node) system, Intel Fortran is run on clusters using MPI and the buffering reduces the number of messages, and thus improves performance.

Also, any option to specify "no buffer" could potentially be implemented as "no buffer beyond line terminator". IOW each "record" is written unbuffered. Your loop is not writing "records".

Jim Dempsey

0 Kudos
Vishnu
Novice
997 Views

Okay, thanks a lot guys!  Kevin, I'm using ifort version 16.0.3 on Linux, if that matters.

Now what do I flag as best reply? Both #2 (Tim) and #7 (Jim) together helped solve it.

0 Kudos
Kevin_D_Intel
Employee
997 Views

Thank you for the ifort version. About the best reply dilemma, our forum only allows picking one. :-(

0 Kudos
Vishnu
Novice
997 Views

Hey Kevin! Try using: CALL FLUSH(6) instead of just FLUSH(6), and then use  ` -assume bscc `  to compile.

0 Kudos
Christian_A_2
Beginner
997 Views

The easiest way for me is to clear the screen... in Windows:

program Progress
    
    use ifport
    use shell32
     
    implicit none
    
    integer::i

    do i=1,10
       res=SYSTEM('cls')
       write(*,*) 'Progress...',i
       call sleep(1)
    enddo

end program Progress

 

0 Kudos
Vishnu
Novice
997 Views

Christian A. wrote:

The easiest way for me is to clear the screen... in Windows:

I guess that is okay if the program doesn't print other things to std_out. In my case it does, so I can't have the whole screen cleared.

0 Kudos
Reply