2: #include <petscsys.h> /*I "petscsys.h" I*/
3: #if defined (PETSC_HAVE_UNISTD_H)
4: #include <unistd.h>
5: #endif
6: #if defined (PETSC_HAVE_STDLIB_H)
7: #include <stdlib.h>
8: #endif
9: #if defined (PETSC_HAVE_DOS_H) /* borland */
10: #include <dos.h>
11: #endif
12: #if defined (PETSC_HAVE_TIME_H)
13: #include <time.h>
14: #endif
18: /*@
19: PetscSleep - Sleeps some number of seconds.
21: Not Collective
23: Input Parameters:
24: . s - number of seconds to sleep
26: Notes:
27: If s is negative waits for keyboard input
29: Level: intermediate
31: Concepts: sleeping
32: Concepts: pause
33: Concepts: waiting
35: @*/
36: PetscErrorCodePetscSleep(PetscReal s) 37: {
39: if (s < 0) getc(stdin);
41: /* Some systems consider it an error to call nanosleep or usleep for more than one second so we only use them for subsecond sleeps. */
42: #if defined (PETSC_HAVE_NANOSLEEP)
43: else if (s < 1) {
44: struct timespec rq;
45: rq.tv_sec = 0;
46: rq.tv_nsec = (long)(s*1e9);
47: nanosleep(&rq,0);
48: }
49: #elif defined (PETSC_HAVE_USLEEP)
50: /* POSIX.1-2001 deprecates this in favor of nanosleep because nanosleep defines interaction with signals */
51: else if (s < 1) usleep((unsigned int)(s*1e6));
52: #endif
54: #if defined (PETSC_HAVE_SLEEP)
55: else sleep((int)s);
56: #elif defined (PETSC_HAVE__SLEEP) && defined(PETSC_HAVE__SLEEP_MILISEC)
57: else _sleep((int)(s*1000));
58: #elif defined (PETSC_HAVE__SLEEP)
59: else _sleep((int)s);
60: #else
61: SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP_SYS,"No support for sleep() on this machine");
62: #endif
63: return(0);
64: }