Skip to content

Instantly share code, notes, and snippets.

@dmarce1
Created September 7, 2018 19:32
Show Gist options
  • Save dmarce1/e33b0f374f29007a5744e255f3fe3167 to your computer and use it in GitHub Desktop.
Save dmarce1/e33b0f374f29007a5744e255f3fe3167 to your computer and use it in GitHub Desktop.
Code to reproduce bug in hpx::lcos::promise
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <valarray>
#define MAX_BUFFER (64*1024)
int main( int argc, char* argv[] ) {
if( argc != 3) {
printf( "average <file> <period>\n" );
abort();
}
double period = atof(argv[2]);
if( period <= 0.0 ) {
printf( "Period must be positive\n" );
abort();
}
static char buffer[MAX_BUFFER];
double entry;
std::vector<std::valarray<double>> data;
FILE* fp = fopen( argv[1], "rt" );
if( fp == NULL ) {
printf( "Unable to open %s\n", argv[1] );
abort();
}
while( !feof(fp) ) {
fgets( buffer, MAX_BUFFER, fp );
char* ptr = buffer;
while( *ptr == ' ' || *ptr == '\t' ) {
ptr++;
}
std::vector<double> row;
while( *ptr != '\n' ) {
entry = atof(ptr);
row.push_back(entry);
while( !(*ptr == ' ' || *ptr == '\t') ) {
ptr++;
}
while( *ptr == ' ' || *ptr == '\t' ) {
ptr++;
}
}
data.push_back(std::valarray<double>(row.data(), row.size()));
}
int head = 0, tail = 0;
for( int i = 0; i < data.size(); i++ ) {
if( data[i][0] - data[0][0] <= period ) {
head++;
} else {
break;
}
}
for( head = head; head < data.size(); head++ ) {
while( data[head][0] - data[tail][0] > period ) {
tail++;
}
double weight_sum = 0.0;
for( int i = tail; i <= head; i++ ) {
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment