-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDiagnosis.cpp
More file actions
57 lines (51 loc) · 1.48 KB
/
Copy pathDiagnosis.cpp
File metadata and controls
57 lines (51 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Diagnosis.cpp:
*
=======================================================*/
#include "mpi.h"
#include "MPI.hpp"
#include "ArrayPool.hpp"
namespace oa{
namespace diag{
bool has_nan_or_inf(ArrayPtr& ap, int skip_sw){
int flag = 0;
switch((ap)->get_data_type()){
///:for t in ['float', 'double']
case DATA_${t.upper()}$:
{
const ${t}$* buf = (${t}$*)(ap)->get_buffer();
Shape s = (ap)->buffer_shape();
int sw = (ap)->get_stencil_width();
Shape as = ap->shape();
int offset_x = (as[0] == 1) ? sw : sw + skip_sw;
int offset_y = (as[1] == 1) ? sw : sw + skip_sw;
int offset_z = (as[2] == 1) ? sw : sw + skip_sw;
for(int k = offset_z; k < s[2] - offset_z; ++k){
for(int j = offset_y; j < s[1] - offset_y; ++j){
for(int i = offset_x; i < s[0] - offset_x; ++i){
if(std::isnan(buf[i + j * s[0] + k * s[0] * s[1]]) ||
std::isinf(buf[i + j * s[0] + k * s[0] * s[1]])){
flag = 1;
}
}
}
}
break;
}
///:endfor
default:
printf("unsupported datatype.\n");
exit(0);
break;
}
int global_flag = 0;
MPI_Comm comm = ap->get_partition()->get_comm();
MPI_Allreduce(&flag, &global_flag, 1, MPI_INT, MPI_SUM, comm);
if(global_flag != 0){
return true;
}else{
return false;
}
}
}
}