mercredi 21 mai 2014

Java - pourrais appliquer le fils dans ce programme pour le rendre plus rapide ? -Débordement de pile


Program: Square number tester


What it does: Tests you on square numbers up to the number you enter


Here's a logic/flow chart of the application



  1. Open/run file

  2. Show an JOptionPane asking the highest number you want to enter

  3. Once entered, show a JFrame with all the questions up to the one you asked

  4. Once done, open a dialogue asking whether you want to retry and show a graph of time taken per question.


Source if anybody wants to see what I have so far: https://github.com/Injustice/SquareNumberTester




It seems not by your description of the procedure.


When considering parallel computing you need to consider what parts of your code can be executed at the same time and if these operations have long computational times. Your procedure seems mostly sequential, i.e., you respond to user inputs and cannot make much use of his thinking time.


Consider 2 cases:



  • Suppose the computational time it takes prepare a questions is long. You need to prepare many questions after a user input.

    • Sequential: you would make the user wait until all the questions are ready, and then sit idle while he answers.

    • Parallel: you prepare the questions during the time the user answers. The "user thread" will ask the "questions preparation" thread for the next question while questions are being added in the background. The "questions preparation" thread is like a buffer for questions.


  • Suppose the computational time it takes to prepare a questions is always shorter than the time it takes the user to answer. In this case there is no difference because there is no waiting time for the user - you prepare the next (one) question while he thinks, and do this repeatedly without needing a questions buffer.


For more information on Java and parallel execution, see the tutorial on concurrency.


For information about speedup relative to "how much parallel or squential the code is", see Amdahl's law.



Program: Square number tester


What it does: Tests you on square numbers up to the number you enter


Here's a logic/flow chart of the application



  1. Open/run file

  2. Show an JOptionPane asking the highest number you want to enter

  3. Once entered, show a JFrame with all the questions up to the one you asked

  4. Once done, open a dialogue asking whether you want to retry and show a graph of time taken per question.


Source if anybody wants to see what I have so far: https://github.com/Injustice/SquareNumberTester



It seems not by your description of the procedure.


When considering parallel computing you need to consider what parts of your code can be executed at the same time and if these operations have long computational times. Your procedure seems mostly sequential, i.e., you respond to user inputs and cannot make much use of his thinking time.


Consider 2 cases:



  • Suppose the computational time it takes prepare a questions is long. You need to prepare many questions after a user input.

    • Sequential: you would make the user wait until all the questions are ready, and then sit idle while he answers.

    • Parallel: you prepare the questions during the time the user answers. The "user thread" will ask the "questions preparation" thread for the next question while questions are being added in the background. The "questions preparation" thread is like a buffer for questions.


  • Suppose the computational time it takes to prepare a questions is always shorter than the time it takes the user to answer. In this case there is no difference because there is no waiting time for the user - you prepare the next (one) question while he thinks, and do this repeatedly without needing a questions buffer.


For more information on Java and parallel execution, see the tutorial on concurrency.


For information about speedup relative to "how much parallel or squential the code is", see Amdahl's law.


0 commentaires:

Enregistrer un commentaire