Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is probably too late but if you write a signal-handler function you can get rid of the memory leaks and reset the device in a sure way:</p> <pre><code>// State variables for extern int no_sigint; int no_sigint = 1; extern int interrupts; int interrupts = 0; /* Catches signal interrupts from Ctrl+c. If 1 signal is detected the simulation finishes the current frame and exits in a clean state. If Ctrl+c is pressed again it terminates the application without completing writes to files or calculations but deallocates all memory anyway. */ void sigint_handler (int sig) { if (sig == SIGINT) { interrupts += 1; std::cout &lt;&lt; std::endl &lt;&lt; "Aborting loop.. finishing frame." &lt;&lt; std::endl; no_sigint = 0; if (interrupts &gt;= 2) { std::cerr &lt;&lt; std::endl &lt;&lt; "Multiple Interrupts issued: " &lt;&lt; "Clearing memory and Forcing immediate shutdown!" &lt;&lt; std::endl; // write a function to free dynamycally allocated memory free_mem (); int devCount; cudaGetDeviceCount (&amp;devCount); for (int i = 0; i &lt; devCount; ++i) { cudaSetDevice (i); cudaDeviceReset (); } exit (9); } } } </code></pre> <p>....</p> <pre><code>int main(){ ..... for (int simulation_step=1 ; simulation_step &lt; SIM_STEPS &amp;&amp; no_sigint; ++simulation_step) { .... simulation code } free_mem(); ... cuda device resets return 0; } </code></pre> <p>If you use this code (you can even include the first snippet in an external header, it works. You can have 2 levels of control of ctrl+c: the first press stops your simulation and exits normally but the application finishes rendering the step which is great to stop gracefully and have correct results, if you press ctrl+c again it closes the application freeing all memory.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload