mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Hardware > GPU Computing

Reply
 
Thread Tools
Old 2012-05-18, 02:24   #1299
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

Quote:
Originally Posted by Prime95 View Post
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
Dubslow is offline   Reply With Quote
Old 2012-05-18, 15:06   #1300
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3·29·83 Posts
Default

Quote:
Originally Posted by Dubslow View Post
Could someone help me understand what this code does?
Quote:
Originally Posted by Batalov View Post
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 View Post
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;
}
And then instead of:
Code:
if( _kbhit() ) { char c = getchar(); /* do something */ }
we could just do
Code:
if( char c=_khbit() ) { /* do something */ }
Dubslow is offline   Reply With Quote
Old 2012-05-18, 16:38   #1301
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
"name field"
Jun 2011
Thailand

22×11×223 Posts
Default

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
LaurV is offline   Reply With Quote
Old 2012-05-18, 17:02   #1302
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

160658 Posts
Default

Quote:
Originally Posted by LaurV View Post
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?)
Dubslow is offline   Reply With Quote
Old 2012-05-18, 17:25   #1303
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
"name field"
Jun 2011
Thailand

981210 Posts
Default

Quote:
Originally Posted by Dubslow View Post
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.
LaurV is offline   Reply With Quote
Old 2012-05-18, 17:28   #1304
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3×29×83 Posts
Default

Quote:
Originally Posted by LaurV View Post
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
Dubslow is offline   Reply With Quote
Old 2012-05-18, 18:00   #1305
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
"name field"
Jun 2011
Thailand

265416 Posts
Default

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
LaurV is offline   Reply With Quote
Old 2012-05-19, 01:01   #1306
Dubslow
Basketry That Evening!
 
Dubslow's Avatar
 
"Bunslow the Bold"
Jun 2011
40<A<43 -89<O<-88

3·29·83 Posts
Default

Quote:
Originally Posted by Dubslow View Post
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
Dubslow is offline   Reply With Quote
Old 2012-05-19, 01:19   #1307
flashjh
 
flashjh's Avatar
 
"Jerry"
Nov 2011
Vancouver, WA

21438 Posts
Default

Quote:
Originally Posted by Dubslow View Post
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.
flashjh is offline   Reply With Quote
Old 2012-05-21, 13:18   #1308
apsen
 
Jun 2011

2038 Posts
Default

I've got a mismatch with 2.0 for 29668031.

Could someone run it with P95?

Thanks,
Andriy
apsen is offline   Reply With Quote
Old 2012-05-21, 22:37   #1309
kdgehman
 
Feb 2011

22×3 Posts
Default

Quote:
Originally Posted by apsen View Post
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
kdgehman is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Don't DC/LL them with CudaLucas LaurV Data 131 2017-05-02 18:41
CUDALucas / cuFFT Performance on CUDA 7 / 7.5 / 8 Brain GPU Computing 13 2016-02-19 15:53
CUDALucas: which binary to use? Karl M Johnson GPU Computing 15 2015-10-13 04:44
settings for cudaLucas fairsky GPU Computing 11 2013-11-03 02:08
Trying to run CUDALucas on Windows 8 CP Rodrigo GPU Computing 12 2012-03-07 23:20

All times are UTC. The time now is 11:07.


Thu Dec 9 11:07:13 UTC 2021 up 139 days, 5:36, 0 users, load averages: 1.25, 1.46, 1.36

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.