Silverfrost Forums

Welcome to our forums

SLEEP SUBROUTINE

20 Dec 2007 9:07 #2528

Hello,

I'm just a fortran beginner; after some days using f77, I've downloaded the Silverfrost FTN95 software including Plato IDE 3.50.

I'd like to ask you a solution to my problem; I want to know how to use Sleep Subroutine because I'm using it as G95 MANUAL says and it doesn't work.

I'm doing something wrong:

**Program Sleep

Integer Year Year = 2007

Print *, 'YEAR IS ', Year Call sleep(100)

Print *, '100 seconds later YEAR IS ', Year

END

SUBROUTINE sleep(seconds) INTEGER, INTENT(IN) :: seconds END SUBROUTINE sleep**

Do you know what is wrong with this code? thanks

F77

21 Dec 2007 7:48 #2532

There is no sleep function in standard Fortran nor in the Salford/Silverfrost Fortran library (that I can think of).

I could point you to a solution but, as a beginner, I do not think that it would help. This would involve calling the sleep function in the Microsoft API.

I am puzzled as to why you would want to use a sleep function in a Fortran program. A sleep function is not provided because there is no obvious reason to need one.

21 Dec 2007 12:09 #2536

Thanks Paul.

I need it because the program I'm coding lasts a lot of time and my computer heats up a lot.

The Sleep Subroutine I posted has been copied from the G95 manual (www.g95.org) as others existing there:

'... SIGNAL SUBROUTINE signal(signal, handler, status) INTEGER, INTENT(IN) :: signal PROCEDURE, INTENT(IN) :: handler INTEGER, INTENT(OUT) :: status END SUBROUTINE signal Interface to the unix signal system call. Sets status to nonzero on error.

SLEEP SUBROUTINE sleep(seconds) INTEGER, INTENT(IN) :: seconds END SUBROUTINE sleep Causes the process to pause for seconds seconds.

SRAND SUBROUTINE srand(seed) INTEGER, INTENT(IN) :: seed END SUBROUTINE srand Re-initializes the random number generator. See the srand() function for details. (page21)'

Even in comp.lang.fortran news, I found a Subroutine Sleep@(time) but yet it doesn't function; perhaps it's for another plataform.

Indeed, I need to put my program 'sleeping' and if you could tell me how, don't be scared with my ignorance, I'm dealing with it a long ago πŸ˜‰ and she is a good girl.

Thank you Paul.

21 Dec 2007 12:16 #2537

Since your SLEEP subroutine contains no code, it shold certainly execute much faster than 100 seconds! If you want to put code into it in the form of a loop, you could repeatedly call one of the FTN95 time-and-date routines (there are many of them - see the help file) and check if 100 seconds have elapsed. Store the first time you get, and compare the new time to that. RETURN when the 100 seconds have elapsed.

However, you will still be disappointed, as there is no way that your code changes the year, which will always report 2007 - even if you run this in 2008.

If you don't want your SLEEP routine to fail if called around midnight, then you have to watch for that case and adjust accordingly.

Turning now to the code you posted, if you run it through FTN95, you will see that your program and the subroutine are both named SLEEP - something FTN95 doesn't think much of. Correct (say) the program name to SLEEPER and it runs.

Just what did you expect to happen?

E

21 Dec 2007 1:23 #2538

Quoted from LitusSaxonicum Since your SLEEP subroutine contains no code, it shold certainly execute much faster than 100 seconds!

Thanks LitusSaxonicum. My intention is to stop the processing of data during a small time, so that the processor stops the full-time usage (100% usage).

If you want to put code into it in the form of a loop, you could repeatedly call one of the FTN95 time-and-date routines (there are many of them - see the help file) and check if 100 seconds have elapsed. Store the first time you get, and compare the new time to that. RETURN when the 100 seconds have elapsed.

However, you will still be disappointed, as there is no way that your code changes the year, which will always report 2007 - even if you run this in 2008.

If you don't want your SLEEP routine to fail if called around midnight, then you have to watch for that case and adjust accordingly.

May be this subroutine makes that:

*Program asd INTEGER SECONDS

.... CALL CPU_TIME(TIME1) .... CALL CPU_TIME(TIME2) SECONDS = TIME2 - TIME1 IF SECONDS > 100 THEN ??? ??? END IF ... ... ... .... END

SUBROUTINE CPU_TIME(TIME) REAL,INTENT(OUT)::TIME END SUBROUTINE*

After knowing that seconds is > 100 how do I stop the processing?

Turning now to the code you posted, if you run it through FTN95, you will see that your program and the subroutine are both named SLEEP - something FTN95 doesn't think much of. Correct (say) the program name to SLEEPER and it runs.

Just what did you expect to happen?

E

Yes it runned. However it didn't 'sleeped' :?

Thanks.

21 Dec 2007 1:31 #2539

My apologies there is indeed a FTN95 routine called SLEEP@.

Here is a sample program...

PRINT*,'This program will terminate in 10 seconds...'
CALL SLEEP@(10.0)
END
21 Dec 2007 4:25 #2540

Quoted from PaulLaidler My apologies there is indeed a FTN95 routine called SLEEP@.

Here is a sample program...

PRINT*,'This program will terminate in 10 seconds...'
CALL SLEEP@(10.0)
END

Great, thanks Paul.

I think that it's called an 'intrinsic function', isnΒ΄t it?

It really pauses the processing but ... it doesn't stop the processor usage. The program goes on in CPU usage = 100% 😦

22 Dec 2007 2:13 #2543

I expect that SLEEP@ repeatedly calls the internal clock, and as a result, makes the cpu rather busy. It makes your program 'sleep', not the cpu.

As regards the cpu getting hot, have you done anything as mundane as taking the side panel off your computer and checking that the cpu heatsink and fan aren't blocked up with dust? Some cheap coolers have sleeve bearings that wear out: the ball bearing type is better but more expensive. Maybe your cooling fan is running slow? You can buy high-powered replacement coolers from a variety of sources, and if you don't mind the noise, extra cooling fans for the case. (Even a new case, with extra fans, might solve the problem). Your cpu should run too hot to touch, but it shouldn't overheat so that it causes errors, even if it is running continuously at 100%.

You may find in the BIOS settings of your computer that you can set the processor to slow down if the temperature exceeds a threshold. I had this once set so that the computer slowed down at normal running temp - it got as far as booting then ran at half speed!

If it isn't the heat INSIDE the computer that is the problem, but the heat that it kicks out when running, then why not try ducting it to the outside? All the exhausts are on the back, so you can even balance it on a window ledge with its backside out of the window! I find that in the summer my home office (which is a wooden house at the end of the garden) used to get unbearably hot. I put the PC outside on the deck and ran the cables in through the window! Flat screens are so much cooler than CRTs that I didn't have to do this last summer at all however.

Eddie

22 Dec 2007 2:47 #2544

Yes you are right. SLEEP@ turns out to be yield process and the name is misleading.

There is an alternative (undocumented) SLEEP1@ that appears to be a genuine sleep process so it does not take over the CPU. It has the same argument.

12 Jan 2008 4:23 #2623

Quoted from PaulLaidler Yes you are right. SLEEP@ turns out to be yield process and the name is misleading.

There is an alternative (undocumented) SLEEP1@ that appears to be a genuine sleep process so it does not take over the CPU. It has the same argument.

Thank you very much Paul πŸ˜„ It functions very well

Sorry for the delay answering to you 😦

12 Jan 2008 4:31 #2624

Quoted from LitusSaxonicum I expect that SLEEP@ repeatedly calls the internal clock, and as a result, makes the cpu rather busy. It makes your program 'sleep', not the cpu.

As regards the cpu getting hot, have you done anything as mundane as taking the side panel off your computer and [color=red:27f7dd977d]checking that the cpu heatsink and fan aren't blocked up with dust?[/color:27f7dd977d] Some cheap coolers have sleeve bearings that wear out: the ball bearing type is better but more expensive. Maybe your cooling fan is running slow? You can buy high-powered replacement coolers from a variety of sources, and if you don't mind the noise, extra cooling fans for the case. (Even a new case, with extra fans, might solve the problem). Your cpu should run too hot to touch, but it shouldn't overheat so that it causes errors, even if it is running continuously at 100%.

You may find in the BIOS settings of your computer that you can set the processor to slow down if the temperature exceeds a threshold. I had this once set so that the computer slowed down at normal running temp - it got as far as booting then ran at half speed!

If it isn't the heat INSIDE the computer that is the problem, but the heat that it kicks out when running, then why not try ducting it to the outside? All the exhausts are on the back, so you can even balance it on a window ledge with its backside out of the window! I find that in the summer my home office (which is a wooden house at the end of the garden) used to get unbearably hot. I put the PC outside on the deck and ran the cables in through the window! Flat screens are so much cooler than CRTs that I didn't have to do this last summer at all however.

Eddie

Yes Eddie you were right. It was the cpu heatsink and fan that were blocked up with dust. I cleaned it as you told me and now no problem with the cpu usage/temp.

Thank you very much πŸ˜„

12 Jan 2008 4:32 #2625

I forgot to wish you guys, Happy New Year πŸ˜ƒ

Please login to reply.