HARM
harm and utilities
 All Data Structures Files Functions Variables Typedefs Macros Pages
fail.c
Go to the documentation of this file.
1 
8 #include "decs.h"
9 
11 int fail(int i, int j, int k, int loc, int fail_type)
12 {
13 
14  // failed use for diag below to avoid bad calculations
15  if(whocalleducon==1) return(1);
16 
17  if(failed==-1){
18  // then just test and return(1) sufficient (i.e. no debug info)
19  }
20  else{
21 
22  dualfprintf(fail_file, "\n\nfail: ti=%d tj=%d tk=%d ft=%d\n",startpos[1]+ i, startpos[2]+j, startpos[3]+k, fail_type);
23 
24 
25 
26  switch (fail_type) {
27  case 1:
28  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR01);
29  break;
30  case 2:
31  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR02);
32  break;
33  case 3:
34  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR03);
35  break;
36  case 4:
37  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR04);
38  break;
39  case 5:
40  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR05);
41  break;
42  case 6:
43  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR06);
44  break;
45  case 7:
46  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR07);
47  break;
48  case 8:
49  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR08);
50  break;
51  case 9:
52  dualfprintf(fail_file, "fail_type=%s\n", FAILSTR09);
53  break;
54  default:
55  dualfprintf(fail_file, "fail_type=unknown\n");
56  break;
57  }
58 
59 
60  dualfprintf(fail_file, "failed\n");
61  // if(area_map(1,FINALTDUMPAREAMAP, 3, i, j, k,GLOBALPOINT(pdump))>=1){}
62  if(area_map(1,FINALTDUMPAREAMAP, NBIGBND, i, j, k,GLOBALPOINT(pdump))>=1){}
63 
64 
65  // do nothing since never will fail since if failed=1, doesn't do fail-related function calls
66 
67  // do not respond here since not in synch with other CPUs. Use postdt().
68  // set falure flag so code stops
69  failed = 1 ;
70  }
71 
72 
73  /* for diagnostic and MPI purposes */
74  return (1);
75 }
76 
84 void postdt(void)
85 {
86  static SFTYPE aftertime,beforetime;
87  static int firsttime=1;
88  static long beforenstep,afternstep;
89  static FTYPE cour0;
90  static int didfail;
91 
92 
93  if(firsttime){
94  cour0=cour;
95  // cour0=0.9;
96 
97  // if no manual failure
98  if(!restartonfail){
99  didfail=0;
100  beforenstep=0;
101  beforetime=aftertime=0;
102  }
103  else{
104  // use to start after failure and manual restart
105  didfail=1;
106  beforetime=911.944419026181;
107  beforenstep=72425;
108  aftertime=t;
109  afternstep=realnstep;
110  }
111  }
112 
113  if((failed)&&(cour>1E-3)){
114  beforenstep=realnstep;
115  beforetime=t;
116  // whichrestart is # of 2nd previous restart since next will use this #
117  if (restart_init(whichrestart) >= 1) {
118  dualfprintf(fail_file, "main:restart_init: failure\n");
119  }
120  afternstep=realnstep;
121  aftertime=t;
122 
123  cour*=0.1;
124  failed=0;
125  didfail=1;
126  }
127  // if((!failed)&&(realnstep>beforenstep+100)){
128  if(didfail&&((!failed)&&(t>beforetime+1)) ){
129  cour=cour0;
130  aftertime=0;
131  afternstep=0;
132  beforetime=0;
133  beforenstep=0;
134  didfail=0;
135  trifprintf("Made it through failiure!\n");
136  }
137  if(failed) myexit(0); // if still failed, then end.
138 
139  // other option is to alter variables right at failure, never
140  // letting this postdt get activated, but that's done elsewhere.
141  firsttime=0;
142 }
143 
144 
146 void setfailresponse(int restartonfailvar)
147 {
148 
149  if(restartonfailvar==0){
150  steptofaildump=(long)pow(2,30);
151  steptofailmap=(long)pow(2,30);
152  dofailmap=0;
153  dofaildump=0;
154  }
155  else{
156  // below is negative to turn off
157  // or positive number of steps
158  // steptofaildump=-1;
159  steptofaildump=(long)pow(2,30); // step number to start full dump each time step
160 
161  steptofailmap=nstep; // start right away
162 
163  // in absolute terms
164  ifail=0;
165  jfail=263;
166  kfail=0;
167 
168  // check per CPU whether response will occur
169  if(
170  ((ifail>=startpos[1])||((mycpupos[1]==0)&&(ifail>=-N1BND))) &&
171  ((ifail<=endpos[1])||((mycpupos[1]==ncpux1-1)&&(ifail<=totalsize[1]-1+N1BND))) &&
172  ((jfail>=startpos[2])||((mycpupos[2]==0)&&(jfail>=-N2BND))) &&
173  ((jfail<=endpos[2])||((mycpupos[2]==ncpux2-1)&&(jfail<=totalsize[2]-1+N2BND))) &&
174  ((kfail>=startpos[3])||((mycpupos[3]==0)&&(kfail>=-N3BND))) &&
175  ((kfail<=endpos[3])||((mycpupos[3]==ncpux3-1)&&(kfail<=totalsize[3]-1+N3BND)))
176  ){
177  dofailmap=1;
178  trifprintf("proc: %d will do fail areamap time series: absolutes: ifail=%d jfail=%d kfail=%d settofaildump=%ld steptofailmap=%ld\n",myid,ifail,jfail,kfail,steptofaildump,steptofailmap);
179  // now set in relative terms
180  ifail-=startpos[1];
181  jfail-=startpos[2];
182  kfail-=startpos[3];
183  trifprintf("proc: %d relative i/j: ifail=%d jfail=%d kfail=%d\n",myid,ifail,jfail,kfail);
184  }
185  else{
186  dofailmap=0;
187  trifprintf("proc: %d will NOT do fail areamap time series\n",myid);
188  }
189  }
190 }
191