From: user1 on
Ron Shepard wrote:
>> Is there a portable way to waste 30 milliseconds?
>
> I know of no standard way in fortran to pause a program for a
> specified time. A nonstandard way might be something like
>
> call system( 'sleep 10' )
>
> to pause for 10 seconds, for example; this does not work for
> fractions of a second, which is the original question. You can
> write a C function that accesses the standard usleep() function,
> which uses units of microseconds, or the nanosleep() function, which
> uses units of nanoseconds. If your compiler supports C
> interoperability, then this approach is standard conforming (through
> C and POSIX). There are some I/O and message passing libraries that
> support sleep functionality (usually by using usleep() or
> nanosleep() under the hood), so if you don't want to write your own
> interface you could link with one of these libraries.
>
> The general advantage of this kind of approach is that the operating
> system sets a timer rather than relying on the CPU spinning with
> wasted work for the sleep period. Perhaps this has more to do with
> esthetics than with practicalities, but I really don't like the idea
> of spinning the CPU with do loops that accomplish nothing useful.
>
> $.02 -Ron Shepard

There are practicalities involved. The method I posted will monopolize the CPU.
A "call delay(10000)" in the code I posted will put 99% cpu usage on the windows
taskmgr for 10 seconds. Fortran could sure use a portable sleep / usleep /
nanosleep function.


From: Gary Scott on
user1 wrote:
> Ron Shepard wrote:
>
>>> Is there a portable way to waste 30 milliseconds?
>>
>>
>> I know of no standard way in fortran to pause a program for a
>> specified time. A nonstandard way might be something like
>>
>> call system( 'sleep 10' )
>>
>> to pause for 10 seconds, for example; this does not work for fractions
>> of a second, which is the original question. You can write a C
>> function that accesses the standard usleep() function, which uses
>> units of microseconds, or the nanosleep() function, which uses units
>> of nanoseconds. If your compiler supports C interoperability, then
>> this approach is standard conforming (through C and POSIX). There are
>> some I/O and message passing libraries that support sleep
>> functionality (usually by using usleep() or nanosleep() under the
>> hood), so if you don't want to write your own interface you could link
>> with one of these libraries.
>>
>> The general advantage of this kind of approach is that the operating
>> system sets a timer rather than relying on the CPU spinning with
>> wasted work for the sleep period. Perhaps this has more to do with
>> esthetics than with practicalities, but I really don't like the idea
>> of spinning the CPU with do loops that accomplish nothing useful.
>>
>> $.02 -Ron Shepard
>
>
> There are practicalities involved. The method I posted will monopolize
> the CPU. A "call delay(10000)" in the code I posted will put 99% cpu
> usage on the windows taskmgr for 10 seconds. Fortran could sure use a
> portable sleep / usleep / nanosleep function.
>
>
yeah, but on Windows, the API for timers is minimum of 1 millisecond.
If you want a faster clock, you have to add hardware. I recently
purchased a discrete card with 3 1-usec timers. You can gang them
together to get a larger signal range. Still, i can only read them
about 7 microseconds per byte. So a 16-bit timer takes 14 microseconds
on average (2Ghz emachines T4200). There was a thread about IVF's
sleepqq having to do with the imprecision of the wakeup process. Even
though the resolution is 1 millisecond, it has a fairly large tolerance
factor.

--

Gary Scott
mailto:garylscott(a)sbcglobal dot net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford