Guest User

Untitled

a guest
Sep 2nd, 2011
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.37 KB | None | 0 0
  1. diff --git a/inc/gCalcFunc.h b/inc/gCalcFunc.h
  2. index 2e4dc52..01e109c 100755
  3. --- a/inc/gCalcFunc.h
  4. +++ b/inc/gCalcFunc.h
  5. @@ -22,6 +22,7 @@ namespace calc {
  6.     extern bool flagcalc;
  7.     extern long double dtime_step;
  8.     extern bool flag_collision;
  9. +   extern std::vector<std::ofstream*> ofstreams;
  10.    
  11.     int calcForce(GravObject* mpmain, GravStep* vmpsinsert, mdv& mdvforcetotal);
  12.     GravStep* calcAcc(GravStep* vmpsinsert, GravStep* vmpsout);
  13. diff --git a/src/gCalcFunc.cpp b/src/gCalcFunc.cpp
  14. index f7b41b2..3e909ea 100755
  15. --- a/src/gCalcFunc.cpp
  16. +++ b/src/gCalcFunc.cpp
  17. @@ -14,6 +14,7 @@ std::bitset<ERROR_CALC_MAX> calc::cerrors;
  18.  bool calc::flagcalc = true;
  19.  long double calc::dtime_step = 0;
  20.  bool calc::flag_collision = true;
  21. +std::vector<std::ofstream*> calc::ofstreams;
  22.  
  23.  /**
  24.   * Calculcate the force between reference object and all the other
  25. @@ -453,8 +454,9 @@ std::bitset<ERROR_CALC_MAX> calc::master(std::string filename, GravStep* pgs_sta
  26.     int percent = 0;
  27.     debugout("CalcCode() - Vars initialized, starting", 15);
  28.     savepercentage(FILE_PERCENT,percent);
  29. -   std::ofstream ofs_temp;
  30. -   ofs_temp.open(filename.c_str(), std::ios::out | std::ios::app);
  31. +   ofstreams.push_back(new std::ofstream(filename.c_str(), std::ios::out | std::ios::app));
  32. +   const std::vector<std::ofstream*>::iterator ofs_iterator = ofstreams.end();
  33. +
  34.  
  35.     while (dtime_sum < dtime_max && flagcalc == true) {
  36.  
  37. @@ -537,7 +539,7 @@ std::bitset<ERROR_CALC_MAX> calc::master(std::string filename, GravStep* pgs_sta
  38.  
  39.         if (dtime_sum >= lstep*dtime_save) {
  40.             debugout("calcMain() - dtime_sum >= lstep*dtime_save", 10);
  41. -           pgs_temp->savetofile(ofs_temp, ++lstep);
  42. +           pgs_temp->savetofile(**ofs_iterator, ++lstep);
  43.             //to be able to communicate with the frontend
  44.             if((dtime_sum*100.0)/dtime_max > percent+1) {
  45.                 if(!savepercentage(FILE_PERCENT,++percent)) {
  46. @@ -562,7 +564,9 @@ std::bitset<ERROR_CALC_MAX> calc::master(std::string filename, GravStep* pgs_sta
  47.     if(percent < 100 && !savepercentage(FILE_PERCENT, 100))
  48.         error::errors |= error::file_out;
  49.  
  50. -   ofs_temp.close();
  51. +   (**ofs_iterator).close();
  52. +   delete (**ofs_iterator);
  53. +   ofstreams.erase(ofs_iterator);
  54.     delete pgs_temp;
  55.     return cerrors;
  56.  }
  57. diff --git a/src/main.cpp b/src/main.cpp
  58. index 2b39f21..ad0bda6 100755
  59. --- a/src/main.cpp
  60. +++ b/src/main.cpp
  61. @@ -6,6 +6,8 @@
  62.  #include <vector>
  63.  #include <cfloat>
  64.  #include <bitset>
  65. +#include <signal.h>
  66. +#include <stdlib.h>
  67.  
  68.  #define MAIN
  69.  
  70. @@ -15,11 +17,34 @@
  71.  #include "gCalcFunc.h"
  72.  #include "gError.h"
  73.  
  74. +void sigterm (int param) {
  75. +   printf ("SIGTERM received - flushing file\n");
  76. +
  77. +   std::vector<std::ofstream*>::iterator ofs;
  78. +        for (ofs = calc::ofstreams.begin(); ofs != calc::ofstreams.end(); ++ofs) {
  79. +       if((**ofs).is_open())
  80. +           (**ofs).close();
  81. +
  82. +       delete (**ofs);
  83. +        }
  84. +
  85. +   remove("KILLED.tmp");
  86. +   exit(1);
  87. +}
  88. +
  89.  int main(int argc, char* pArgs[]) {
  90.     std::string filename;
  91.     GravDataSet* pgdsStart = new GravDataSet();
  92.     long double dtime_step_default = -1;
  93.  
  94. +   /* Overwrite SIGTERM in order to flush file */
  95. +   {
  96. +   void (*signal_previous)(int);
  97. +   signal_previous = signal(SIGTERM,sigterm);
  98. +   if (signal_previous==SIG_IGN)
  99. +       signal(SIGTERM,SIG_IGN);
  100. +   }
  101. +
  102.     for(int i=1; i < argc ; i++) {
  103.         if( (std::string)pArgs[i] == FLAG_DEBUG1 || (std::string)pArgs[i] == FLAG_DEBUG2) {
  104.             std::cout << "Frontend: " << FVERSION << std::endl;
Advertisement
Add Comment
Please, Sign In to add comment