mersenneforum.org CUDALucas (a.k.a. MaclucasFFTW/CUDA 2.3/CUFFTW)
 Register FAQ Search Today's Posts Mark Forums Read

2012-05-18, 02:24   #1299
Dubslow

"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

160658 Posts

Quote:
 Originally Posted by Prime95 Submit the successful triple-check first. If you submit the bad double-check first, then there is a window where the server will make the exponent available to some poor unsuspecting user for a triple-check.
Indeed. If you submit, nothing happens -- if I submit, I lose the assignment for the exponent.

Hmm, I only just now read that I was wrong. I guess the lesson is don't upgrade drivers during a test... first mismatch I've had with 2.00. (Out of 8-10 or so. I'm not on 2.01 yet, though I will be soon.)

Last fiddled with by Dubslow on 2012-05-18 at 02:27

2012-05-18, 15:06   #1300
Dubslow

"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts

Quote:
 Originally Posted by Dubslow Could someone help me understand what this code does?
Quote:
 Originally Posted by Batalov Looks like it checks if a key was pressed, and if so, put it back in the queue but signal the caller that a character can now be retrieved. P.S. A copy of the normal term i/o handler is created except it is now non-blocking. If you ask for a char from normal code, it will sit doing nothing _until_ you press the key. Here, this routine will report to the caller - "there was no activity, carry on".
Quote:
 Originally Posted by LaurV Because in that case (your code) the computer is locked until you decide to press the dammit key. The monkey bar joke. When I was child I did a lot of quarters with "I bet you a quarter you can't hang on it until I count to 10". Many of my friends took the bet, then I was counting very fast to 9, and going away living them hanging on the bar. Eventually they felt down and lost the bet, because they could not hold on it until I counted to 10. The original code does a lot of work to modify the behavior of the getchar() routine to return immediately in case no key was already pressed, without waiting for the key, and if a key was pressed, to get its scan code, (accepting key combinations, like CTRL+ALT+F12), and terminate if ctrl+c was pressed. After the key is read, the old behavior (waiting for the key) is restored. Se for details here and here (follow the fork link in that post).
If I only cared about the first character, could I do something like this?
Code:
char
_kbhit (void)
{
struct termios oldt, newt;
int ch;
int oldf;

tcgetattr (STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr (STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl (STDIN_FILENO, F_GETFL, 0);
fcntl (STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);

ch = getchar ();

tcsetattr (STDIN_FILENO, TCSANOW, &oldt);
fcntl (STDIN_FILENO, F_SETFL, oldf);

if (ch != EOF)
{
ungetc (ch, stdin);
return 1;

return ch;
}

return 0;
}
Code:
if( _kbhit() ) { char c = getchar(); /* do something */ }
we could just do
Code:
if( char c=_khbit() ) { /* do something */ }

 2012-05-18, 16:38 #1301 LaurV Romulan Interpreter     "name field" Jun 2011 Thailand 268316 Posts You then may need to process all the characters, and return back to the OS the characters which are not yours. Otherwise you just hooked the kbd for yourself for as long as the program is running... In single task your modification would work perfect. Now imagine you have multitasking and some process in the background is calling kbhit in a loop (therefore discarding all the characters that enters the buffer of the peripheral). There will be no way for you to input something, in your foreground process (calculator, text editor, cmd line, whatever). Returning the character (instead of 1) is ok, and maybe useful, but "not putting it back in the buffer" is a bad practice. Some other guys in the system may need it. edit: Last fiddled with by LaurV on 2012-05-18 at 16:50
2012-05-18, 17:02   #1302
Dubslow

"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts

Quote:
 Originally Posted by LaurV You then may need to process all the characters, and return back to the OS the characters which are not yours. Otherwise you just hooked the kbd for yourself for as long as the program is running... In single task your modification would work perfect. Now imagine you have multitasking and some process in the background is calling kbhit in a loop (therefore discarding all the characters that enters the buffer of the peripheral). There will be no way for you to input something, in your foreground process (calculator, text editor, cmd line, whatever). Returning the character (instead of 1) is ok, and maybe useful, but "not putting it back in the buffer" is a bad practice. Some other guys in the system may need it. edit:
Well, we're talking about a terminal which is controlled by the program running. Even the first option, the guy calling kbhit() just re-gets the char anyways. (Perhaps a supermod could move these posts to the programming forum?)

2012-05-18, 17:25   #1303
LaurV
Romulan Interpreter

"name field"
Jun 2011
Thailand

985910 Posts

Quote:
 Originally Posted by Dubslow Well, we're talking about a terminal which is controlled by the program running. Even the first option, the guy calling kbhit() just re-gets the char anyways. (Perhaps a supermod could move these posts to the programming forum?)
There is only ONE kbd buffer. Your terminal uses it, as the text editor uses it, as the OS itself uses it. Same idea is used by programs like "snagit" or whatever, which defines "hotkeys". You press alt+f11 in any window you are, snagit pops up and copy the window content in a gif. Now assume snagit will read all the keys, and if it is not his key, just discard it. You won't be able to use the kbd anymore.

2012-05-18, 17:28   #1304
Dubslow

"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts

Quote:
 Originally Posted by LaurV There is only ONE kbd buffer. Your terminal uses it, as the text editor uses it, as the OS itself uses it. Same idea is used by programs like "snagit" or whatever, which defines "hotkeys". You press alt+f11 in any window you are, snagit pops up and copy the window content in a gif. Now assume snagit will read all the keys, and if it is not his key, just discard it. You won't be able to use the kbd anymore.
What text-editor? I'm talking about the -k switch from CUDALucas, hence why I don't care about the characters after the first one. (or at least, how to port that code to MPrime).

Last fiddled with by Dubslow on 2012-05-18 at 17:35

 2012-05-18, 18:00 #1305 LaurV Romulan Interpreter     "name field" Jun 2011 Thailand 9,859 Posts I was talking "generally". Put the char back into the buffer. Why this bothers you? Let the OS do whatever he likes with it (for example printing it on screen, otherwise you have even to print it by yourself). I don't know what you wanna do "particularly". Try experimenting. This is how you learn :D Keep the version that works as you like. Now really a mod should move these posts... Last fiddled with by LaurV on 2012-05-18 at 18:01
2012-05-19, 01:01   #1306
Dubslow

"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

1C3516 Posts

Quote:
 Originally Posted by Dubslow I guess the lesson is don't upgrade drivers during a test... first mismatch I've had with 2.00. (Out of 8-10 or so. I'm not on 2.01 yet, though I will be soon.)
Well, I accidentally installed another update during the next test and that matched, so... cosmic ray?

Last fiddled with by Dubslow on 2012-05-19 at 01:02 Reason: Link

2012-05-19, 01:19   #1307
flashjh

"Jerry"
Nov 2011
Vancouver, WA

112310 Posts

Quote:
 Originally Posted by Dubslow Well, I accidentally installed another update during the next test and that matched, so... cosmic ray?
I had really bad luck with 2.00. 2.01 seems better for me, but I haven't done DC in a while since I moved all my cards to TF for a while.

 2012-05-21, 13:18 #1308 apsen   Jun 2011 100000112 Posts I've got a mismatch with 2.0 for 29668031. Could someone run it with P95? Thanks, Andriy
2012-05-21, 22:37   #1309
kdgehman

Feb 2011

1210 Posts

Quote:
 Originally Posted by apsen I've got a mismatch with 2.0 for 29668031. Could someone run it with P95? Thanks, Andriy

M29668031, Lucas-Lehmer test, Fri May 25 23:00 2012

Last fiddled with by kdgehman on 2012-05-21 at 22:44

 Similar Threads Thread Thread Starter Forum Replies Last Post LaurV Data 131 2017-05-02 18:41 Brain GPU Computing 13 2016-02-19 15:53 Karl M Johnson GPU Computing 15 2015-10-13 04:44 fairsky GPU Computing 11 2013-11-03 02:08 Rodrigo GPU Computing 12 2012-03-07 23:20

All times are UTC. The time now is 10:13.

Tue Jan 18 10:13:14 UTC 2022 up 179 days, 4:42, 0 users, load averages: 1.48, 1.54, 1.41