|
CS471/571 - Operating Systems
| Displaying exercises/e5/files/e5.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#define DATASIZE 100 * 1024 * 1024
long value;
unsigned char *data;
/**
* Compile with gcc -o e5 e5.c -lm
*/
void compute_value(void)
{
for(int i=0; i < DATASIZE; i++)
value += (long)cos(sqrt((double)data[i]));
}
int main(int argc, char *argv[])
{
/* Leave the following unmodified: */
if (argc > 1) srand(atoi(argv[1]));
value = 0;
data = malloc(sizeof(unsigned char) * DATASIZE);
printf("Generating data...\n");
for(int i=0; i < DATASIZE; i++) {
data[i] = (unsigned char)(rand() % 100);
}
/* Add thread support from here: */
printf("Computing...\n");
compute_value();
printf("%ld\n", value);
return 0;
}
|