-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathInputOutput.cpp
More file actions
70 lines (51 loc) · 2.11 KB
/
InputOutput.cpp
File metadata and controls
70 lines (51 loc) · 2.11 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
58
59
60
61
62
63
64
65
66
67
68
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include "InputOutput.h"
#define prec_save 15
/***********************************************/
/* SAVE INDIVIDUAL REAL CPU MATRIX TO txt FILE */
/***********************************************/
template <class T>
void saveCPUrealtxt(const T * h_in, const char *filename, const int M) {
std::ofstream outfile;
outfile.open(filename);
for (int i = 0; i < M; i++) outfile << std::setprecision(prec_save) << h_in[i] << "\n";
outfile.close();
}
template void saveCPUrealtxt<float>(const float *, const char *, const int);
template void saveCPUrealtxt<double>(const double *, const char *, const int);
/**************************************************/
/* SAVE INDIVIDUAL INTEGER CPU MATRIX TO txt FILE */
/**************************************************/
template <class T>
void saveCPUintegertxt(const T * h_in, const char *filename, const int M) {
std::ofstream outfile;
outfile.open(filename);
for (int i = 0; i < M; i++) outfile << h_in[i] << "\n";
outfile.close();
}
template void saveCPUintegertxt<int>(const int *, const char *, const int);
/****************************************************/
/* LOAD INDIVIDUAL REAL MATRIX FROM txt FILE TO CPU */
/****************************************************/
// --- Load individual real matrix from txt file
template <class T>
void loadCPUrealtxt(T * __restrict h_out, const char *filename, const int M) {
//T * loadCPUrealtxt(T * __restrict h_out, const char *filename, const int M) {
//h_out = (T *)malloc(M * sizeof(T));
std::ifstream infile;
infile.open(filename);
for (int i = 0; i < M; i++) {
double temp;
infile >> temp;
h_out[i] = (T)temp;
}
infile.close();
//return h_out;
}
template void loadCPUrealtxt<int>(int * __restrict, const char *, const int);
template void loadCPUrealtxt<float>(float * __restrict, const char *, const int);
template void loadCPUrealtxt<double>(double * __restrict, const char *, const int);
//template float * loadCPUrealtxt<float>(float * __restrict, const char *, const int);
//template double * loadCPUrealtxt<double>(double * __restrict, const char *, const int);