Skip to content

Commit

Permalink
Added chunking to ttd-g2 and disabled final output when chunking enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
steinbrecher committed Aug 11, 2017
1 parent 2f86c32 commit c167a28
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/pq-utils/pq_gn.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ int pq_g2_many(char* infile, char* outfile_prefix) {


// Output the g2 files
if (run_g2) {
if (run_g2 && (pq_gn_cli_args.chunk_time == 0)) {
fprintf(stderr, "\n");

for (i = 0; i < num_pairs; i++) {
Expand Down Expand Up @@ -650,7 +650,7 @@ int pq_g2_many(char* infile, char* outfile_prefix) {
size_t num_bins;
_Bool allSame = 1;

if ((run_g2) && (num_pairs > 1)) {
if ((run_g2) && (num_pairs > 1) && (pq_gn_cli_args.chunk_time == 0)) {

num_bins = g2_ccorrs[0].num_bins;
for (i = 1; i < num_pairs; i++) {
Expand Down
5 changes: 4 additions & 1 deletion src/pq-utils/pq_gn_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ void pq_gn_print_options(int no_verbose) {

fprintf(stderr, KHEAD2 "Bin time: " KNRM KTIME "%'" PRIu64 " ps\n" KNRM, pq_gn_cli_args.bin_time);
fprintf(stderr, KHEAD2 "Window time: " KNRM KTIME "%'" PRIu64 " ps\n" KNRM, pq_gn_cli_args.window_time);
fprintf(stderr, KHEAD2 "Chunk time: " KNRM KTIME "%'" PRIu64 " ps\n" KNRM, pq_gn_cli_args.chunk_time);
if (pq_gn_cli_args.chunk_time > 0) {
fprintf(stderr, KHEAD2 "Chunk time: " KNRM KTIME "%'" PRIu64 " ps\n" KNRM, pq_gn_cli_args.chunk_time);
}


int i;
fprintf(stderr, "\n");
Expand Down
30 changes: 28 additions & 2 deletions src/ttd-utils/ttd_g2.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdio.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

#include "ttd_g2_cli.h"

Expand All @@ -13,7 +14,19 @@
// Note: Make sure to clean up and then free the ccorr object generated by this function
ttd_ccorr2_t *ttd_g2(char* infile1, char* infile2, int *retcode) {
ttd_t t1, t2;
ttd_t nextChunkTime = ttd_g2_cli_args.chunk_time;
ttd_ccorr2_t *ccorr = ttd_ccorr2_build(ttd_g2_cli_args.bin_time, ttd_g2_cli_args.window_time, 256);
size_t outlen = strlen(ttd_g2_cli_args.outfile);
char outfilePrefix[outlen];
char outfile[outlen+20];
size_t i;
// Truncate outfile into outfilePrefix
for (i=0; i<outlen-4; i++) {
outfilePrefix[i] = ttd_g2_cli_args.outfile[i];
}
size_t chunkNum = 0;

printf("Outfile prefix: %s\n", outfilePrefix);

if (ccorr->hist == NULL) {
printf("ERROR: Histogram not allocated");
Expand All @@ -38,6 +51,16 @@ ttd_ccorr2_t *ttd_g2(char* infile1, char* infile2, int *retcode) {
t2 = ttd_fb_pop(&fb2);

while((fb1.empty == 0) && (fb2.empty == 0)) {
if (ttd_g2_cli_args.chunk_time > 0) {
if ((t1 > nextChunkTime) || (t2 > nextChunkTime)) {
sprintf(outfile, "%s_chunk%lu.csv", outfilePrefix, chunkNum);
ttd_ccorr2_write_csv(ccorr, outfile, ttd_g2_cli_args.normalize, ttd_g2_cli_args.int_time,
ttd_g2_cli_args.window_time);
memset(ccorr->hist, 0, sizeof(ttd_t) * ccorr->num_bins);
nextChunkTime += ttd_g2_cli_args.chunk_time;
chunkNum++;
}
}
if (t1 <= t2) {
ttd_ccorr2_update(ccorr, 0, t1);
t1 = ttd_fb_pop(&fb1);
Expand Down Expand Up @@ -107,8 +130,11 @@ int main(int argc, char* argv[]) {


ttd_ccorr2_t *g2_ccorr = ttd_g2(infile1, infile2, &retcode);

ttd_ccorr2_write_csv(g2_ccorr, outfile, ttd_g2_cli_args.normalize, ttd_g2_cli_args.int_time, ttd_g2_cli_args.window_time);

if (ttd_g2_cli_args.chunk_time == 0) {
ttd_ccorr2_write_csv(g2_ccorr, outfile, ttd_g2_cli_args.normalize, ttd_g2_cli_args.int_time,
ttd_g2_cli_args.window_time);
}


ttd_ccorr2_cleanup(g2_ccorr);
Expand Down
11 changes: 10 additions & 1 deletion src/ttd-utils/ttd_g2_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ static const struct option ttd_g2_longopts[] = {

{ "bin-time", required_argument, NULL, 'b' },
{ "window-time", required_argument, NULL, 'w' },
{ "chunk-time", required_argument, NULL, 'c' },
{ "input2-offset", required_argument, NULL, 'T' },

{ "block-size", required_argument, NULL, 'B' },
{ "ringbuffer-size", required_argument, NULL, 'R' },


};

static const char *ttd_g2_optstring = "VhvNt:1:2:o:T:b:w:B:R:";
static const char *ttd_g2_optstring = "VhvNt:1:2:o:T:b:w:c:B:R:";

void ttd_g2_cli_print_help(char* program_name) {
// Need a string of spaces equal in length to the program name
Expand Down Expand Up @@ -80,6 +82,7 @@ int ttd_g2_read_cli(int argc, char* argv[]) {

int window_time_set = 0;
ttd_g2_cli_args.window_time = 10000;
ttd_g2_cli_args.chunk_time = 0;
ttd_g2_cli_args.infile2_offset = 0;

ttd_g2_cli_args.block_size = 16384;
Expand Down Expand Up @@ -138,6 +141,9 @@ int ttd_g2_read_cli(int argc, char* argv[]) {
ttd_g2_cli_args.window_time = sci_to_int64(optarg, &retcode);
window_time_set = 1;
break;
case 'c':
ttd_g2_cli_args.chunk_time = sci_to_int64(optarg, &retcode);
break;
case 'T':
ttd_g2_cli_args.infile2_offset = sci_to_int64(optarg, &retcode);

Expand Down Expand Up @@ -180,6 +186,9 @@ void ttd_g2_print_options(int no_verbose) {
}
printf("Bin time: %" PRIu64 " ps\n", ttd_g2_cli_args.bin_time);
printf("Window time: %" PRIu64 " ps\n", ttd_g2_cli_args.window_time);
if (ttd_g2_cli_args.chunk_time > 0) {
printf("Chunk time: %" PRIu64 " ps\n", ttd_g2_cli_args.chunk_time);
}
printf("Offset file 2 times by %" PRId64 " ps\n", ttd_g2_cli_args.infile2_offset);
printf("Block size: %d records\n", ttd_g2_cli_args.block_size);
}
Expand Down
1 change: 1 addition & 0 deletions src/ttd-utils/ttd_g2_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct {

ttd_t bin_time; // -b
ttd_t window_time; // -w
ttd_t chunk_time; // -c
int64_t infile2_offset; // -T (note signed time for negative shifts)

int block_size; // -B
Expand Down

0 comments on commit c167a28

Please sign in to comment.