server-side-compute/test/reduce-traditional.c

38 lines
644 B
C
Raw Normal View History

2019-08-20 14:54:18 +00:00
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <stdint.h>
#include <stdbool.h>
#include <float.h>
2019-08-20 15:51:25 +00:00
#include <math.h>
2019-08-20 14:54:18 +00:00
/*
* This application shows a traditional reduce operation
*/
// read the data and reduce it
void reduce_data(int size){
float * data = malloc(size * sizeof(float));
FILE * file = fopen("data.bin", "rb");
fread(data, size*sizeof(float), 1, file);
fclose(file);
2019-08-20 15:51:25 +00:00
float mx = -INFINITY;
2019-08-20 14:54:18 +00:00
for(int i=0; i < size; i++){
mx = data[i] > mx ? data[i]: mx;
}
free(data);
printf("Maximum: %f\n", mx);
}
int main(){
int size = 100;
reduce_data(size);
return 0;
}