forked from VolunteerComputingHelp/boinc-app-eah-brp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemod_binary_hs_cpu.c
104 lines (84 loc) · 4.11 KB
/
demod_binary_hs_cpu.c
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
/***************************************************************************
* Copyright (C) 2010 by Oliver Bock *
* oliver.bock[AT]aei.mpg.de *
* Copyright (C) 2010 by Heinz-Bernd Eggenstein *
* *
* This file is part of Einstein@Home (Radio Pulsar Edition). *
* *
* Description: *
* Performs harmonic summing (2nd ... 16th harmonic) of powerspectrum *
* CPU variant. *
* *
* Einstein@Home is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published *
* by the Free Software Foundation, version 2 of the License. *
* *
* Einstein@Home is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Einstein@Home. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "demod_binary_hs_cpu.h"
#include "erp_utilities.h"
#include "hs_common.h"
#include "demod_binary.h"
int set_up_harmonic_summing(float **sumspec,int32_t ** dirty,unsigned int * nr_pages_ptr,unsigned int fundamental_idx_hi, unsigned int harmonic_idx_hi)
{
int i;
unsigned int nr_pages = (fundamental_idx_hi >> LOG_PS_PAGE_SIZE ) +1;
*nr_pages_ptr = nr_pages;
// allocate memory for the harmonic summed spectra and dirty pages array
for( i = 1; i < 5; i++) {
sumspec[i] = (float *) calloc(fundamental_idx_hi, sizeof(float));
if(sumspec[i] == NULL) {
logMessage(error, true, "Couldn't allocate %d bytes of memory for sumspec at bottom level.\n", fundamental_idx_hi * sizeof(float));
return(RADPUL_EMEM);
}
}
for( i = 0; i < 5; i++) {
dirty[i] = (int32_t *) calloc(nr_pages, sizeof(int32_t));
if(dirty[i] == NULL) {
logMessage(error, true, "Couldn't allocate %d bytes of memory for sumspec page flag at bottom level.\n", fundamental_idx_hi * sizeof(int32_t));
return(RADPUL_EMEM);
}
}
return 0;
}
int run_harmonic_summing(float **sumspec, int32_t ** dirty_flags, unsigned int nr_pages,
DIfloatPtr powerspectrum_dip, unsigned int window_2, unsigned int fundamental_idx_hi,
unsigned int harmonic_idx_hi, float *thresholds)
{
int result,i;
float * powerspectrum = powerspectrum_dip.host_ptr;
// zero out sumspec array
// TODO: necessary?
for( i = 1; i < 5; i++) {
memset(sumspec[i], 0, fundamental_idx_hi * sizeof(float));
}
// zero out dirty pages flags array
for( i = 0; i < 5; i++) {
memset(dirty_flags[i], 0, nr_pages * sizeof(float));
}
// add powerspectrum as first spectra element
sumspec[0] = powerspectrum;
result = harmonic_summing(sumspec, dirty_flags,powerspectrum, window_2, fundamental_idx_hi, harmonic_idx_hi,thresholds);
return result;
}
int tear_down_harmonic_summing(float **sumspec, int32_t ** dirty)
{
int i;
// clean up (0th element is powerspectrum, freed separately)
for(i = 1; i < 5; i++) {
free(sumspec[i]);
}
for(i = 0; i < 5; i++) {
free(dirty[i]);
}
return 0;
}