-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
119 lines (97 loc) · 4.86 KB
/
main.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
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2019 Adam Campbell, Seth Hall, Andrew Ensor
// Copyright 2019 High Performance Computing Research Laboratory, Auckland University of Technology (AUT)
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include "gridder.h"
int main(int argc, char **argv)
{
Config config;
init_config(&config);
printf(">>> UPDATE: Determining memory requirements for convolution kernels...\n");
int2 *kernel_supports = (int2*) calloc(config.num_wproj_kernels, sizeof(int2));
if(kernel_supports == NULL)
{
printf(">>> ERROR: unable to allocate memory for kernel supports, terminating...\n");
clean_up(NULL, NULL, NULL, NULL, &kernel_supports, NULL);
return EXIT_FAILURE;
}
int total_samples_needed = read_kernel_supports(&config, kernel_supports);
if(total_samples_needed <= 0)
{
printf(">>> ERROR: unable to read kernel samples from file, terminating...\n");
clean_up(NULL, NULL, NULL, NULL, &kernel_supports, NULL);
return EXIT_FAILURE;
}
printf(">>> UPDATE: Requirements analysis complete...\n");
printf(">>> UPDATE: Allocating resources for grid and convolution kernels...\n");
Complex *grid = (Complex*) calloc(config.grid_size * config.grid_size, sizeof(Complex));
Complex *kernel = (Complex*) calloc(total_samples_needed, sizeof(Complex));
if(grid == NULL || kernel == NULL)
{
printf(">>> ERROR: unable to allocate memory for grid/kernels, terminating...\n");
clean_up(&grid, NULL, NULL, &kernel, &kernel_supports, NULL);
return EXIT_FAILURE;
}
printf(">>> UPDATE: Resource allocation successful...\n");
printf(">>> UPDATE: Loading kernels...\n");
bool loaded_kernel = load_kernel(&config, kernel, kernel_supports);
if(!loaded_kernel)
{
printf(">>> ERROR: Unable to open kernel source files, terminating...\n");
clean_up(&grid, NULL, NULL, &kernel, &kernel_supports, NULL);
return EXIT_FAILURE;
}
printf(">>> UPDATE: Loading kernels complete...\n");
printf(">>> UPDATE: Loading visibilities...\n");
Visibility *vis_uvw = NULL;
Complex *vis_intensities = NULL;
bool loaded_vis = load_visibilities(&config, &vis_uvw, &vis_intensities);
if(!loaded_vis || !vis_uvw)
{ printf(">>> ERROR: Unable to load grid or read visibility files, terminating...\n");
clean_up(&grid, &vis_uvw, &vis_intensities, &kernel, &kernel_supports, NULL);
return EXIT_FAILURE;
}
printf(">>> UPDATE: Loading visibilities complete...\n");
printf(">>> UPDATE: LOADING IN CONVOLUTION KERNEL SAMPLES... \n");
PRECISION *prolate = (PRECISION*) calloc(config.grid_size / 2, sizeof(PRECISION));
create_1D_half_prolate(prolate, config.grid_size);
if(!prolate)
{
printf("ERROR: Unable to allocate memory for the 1D prolate spheroidal \n");
clean_up(&grid, &vis_uvw, &vis_intensities, &kernel, &kernel_supports, &prolate);
return EXIT_FAILURE;
}
printf(">>> UPDATE: Performing W-Projection based convolutional gridding...\n");
execute_gridding(&config, grid, vis_uvw, vis_intensities, config.num_visibilities,
kernel, kernel_supports, total_samples_needed, prolate);
printf(">>> UPDATE: Gridding complete...\n");
printf(">>> UPDATE: Saving grid to file...\n");
save_grid_to_file(&config, grid, 0,config.grid_size,0,config.grid_size);
printf(">>> UPDATE: Save successful...\n");
printf(">>> UPDATE: Cleaning up allocated resources...\n");
clean_up(&grid, &vis_uvw, &vis_intensities, &kernel, &kernel_supports, &prolate);
printf(">>> UPDATE: Cleaning complete, exiting...\n");
return EXIT_SUCCESS;
}