-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfratio_master.cpp
107 lines (93 loc) · 3.88 KB
/
fratio_master.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// Created by wsl on 4/19/17.
//
#include "data.h"
#include "cmd_master.h"
#include <fstream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include "sagecal.h"
#include "utils.h"
#include "utils_dn.h"
using namespace std;
using namespace Data;
int fratio_master(dlg_app_info *app) {
Data::MPIData mpiData;
int ntasks = 0;
vector <struct MsIndex> msIndexs;
/*------------------------------------share data file-------------------------------------------------------------*/
char shareFile[256];
sprintf(shareFile,"%s/v.mastershare",Data::shareDir);
FILE *sp = 0;
if ((sp = fopen(shareFile, "rb")) == 0) {
fprintf(stderr, "%s: %d: no output file\n", __FILE__, __LINE__);
return 1;
}
load_mpidata(sp, &mpiData);
fread(&ntasks, sizeof(int), 1, sp);
for (unsigned int cm = 0; cm <ntasks; cm++) {
struct MsIndex msIndex;
fread(&msIndex, sizeof(struct MsIndex), 1, sp);
msIndexs.push_back(msIndex);
}
if (sp) {
fclose(sp);
}
/*------------------------------------input ----------------------------------------------------------------------*/
double *fratio;
if ((fratio = (double *) calloc((size_t) mpiData.Nms, sizeof(double))) == 0) {
fprintf(stderr, "%s: %d: no free memory\n", __FILE__, __LINE__);
exit(1);
}
double *B, *Bi;
/* Npoly terms, for each frequency, so Npoly x Nms */
if ((B = (double *) calloc((size_t) Npoly * mpiData.Nms, sizeof(double))) == 0) {
fprintf(stderr, "%s: %d: no free memory\n", __FILE__, __LINE__);
exit(1);
}
/* pseudoinverse */
if ((Bi = (double *) calloc((size_t) Npoly * Npoly, sizeof(double))) == 0) {
fprintf(stderr, "%s: %d: no free memory\n", __FILE__, __LINE__);
exit(1);
}
read_share_XYZ(Data::shareDir, "master", fratio, mpiData.Nms, "fratio");
read_share_XYZ(Data::shareDir, "master", B, Npoly * mpiData.Nms, "B");
read_share_XYZ(Data::shareDir, "master", Bi, Npoly * Npoly, "Bi");
int flag = 0;
for (unsigned int cm = 0; cm < app->n_inputs; cm++) {
app->inputs[cm].read((char *)&flag, sizeof(int));
if (flag == 0) {
Data::IOData data;
load_iodata_dn_noprefix(&(app->inputs[cm]), &data);
// cout << "[fratio_master]========, data.N/M/Mt/Nms:" << data.N << "/" << data.M << "/"
// << data.Mt << "/" << data.Nms << ", data.freq0:" << data.freq0/ 1e6<< "Mhz" << endl;
char short_name[128], ms_full_name[256];
sprintf(ms_full_name,"%s", data.msname);
ms_short_name(ms_full_name, short_name);
for (unsigned int sm = 0; sm < msIndexs.size(); sm++) {
if(strcmp(short_name, msIndexs[sm].ms)==0) {
fratio[msIndexs[sm].cm] = data.fratio;
break;
}
}
Data::freeData(data);
}
}
/*---------------------------------------find_prod_inverse--------------------------------------------------------*/
/* interpolation polynomial */
find_prod_inverse(B, Bi, Npoly, mpiData.Nms, fratio);
/*----------------------------------------share output------------------------------------------------------------*/
write_share_XYZ(Data::shareDir, "master", fratio, mpiData.Nms, "fratio");
write_share_XYZ(Data::shareDir, "master", B, Npoly * mpiData.Nms, "B");
write_share_XYZ(Data::shareDir, "master", Bi, Npoly * Npoly, "Bi");
/*-------------------------------------------output---------------------------------------------------------------*/
dump_mpidata_dn(&(app->outputs[0]), &mpiData);
/*--------------------------------------------- free ----------------------------------------------------------*/
free(B);
free(Bi);
free(fratio);
delete[] mpiData.freqs;
cout << "[fratio_master]========,Done." << endl;
return 0;
}