80 lines
1.7 KiB
Plaintext
80 lines
1.7 KiB
Plaintext
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "cuda_runtime.h"
|
|
#include "device_launch_parameters.h"
|
|
|
|
typedef struct configuration {
|
|
int n;
|
|
float north;
|
|
float east;
|
|
float south;
|
|
float west;
|
|
float init_value;
|
|
float threshold;
|
|
} configuration;
|
|
|
|
__host__ int old_load_config(configuration *config) {
|
|
config->n = 5;
|
|
config->north = 0.0;
|
|
config->east = 0.0;
|
|
config->west = 0.0;
|
|
config->south = 300.0;
|
|
config->init_value = 0.0;
|
|
config->threshold = 1.0;
|
|
return 0;
|
|
}
|
|
|
|
__host__ int load_config(configuration *config) {
|
|
char property[100];
|
|
char *value;
|
|
FILE *fp;
|
|
|
|
fp = fopen("jacobi.conf", "r");
|
|
if (fp == NULL) {
|
|
perror("Error opening file jacobi.conf");
|
|
return 1;
|
|
}
|
|
while (fgets(property, 100, fp) != NULL) {
|
|
if (property[0] == '\n' || property[0] == '#') {
|
|
/* Skip empty lines and comments */
|
|
continue;
|
|
}
|
|
value = strchr(property, ' ');
|
|
if (value == NULL) {
|
|
fclose(fp);
|
|
perror("Error reading file jacobi.conf");
|
|
return 1;
|
|
}
|
|
value[0] = '\0';
|
|
value += sizeof(char);
|
|
value[strlen(value) - 1] = '\0';
|
|
if (strcmp(property, "N") == 0) {
|
|
sscanf(value, "%d", &(config->n));
|
|
}
|
|
else if (strcmp(property, "NORTH") == 0) {
|
|
sscanf(value, "%f", &(config->north));
|
|
}
|
|
else if (strcmp(property, "EAST") == 0) {
|
|
sscanf(value, "%f", &(config->east));
|
|
}
|
|
else if (strcmp(property, "SOUTH") == 0) {
|
|
sscanf(value, "%f", &(config->south));
|
|
}
|
|
else if (strcmp(property, "WEST") == 0) {
|
|
sscanf(value, "%f", &(config->west));
|
|
}
|
|
else if (strcmp(property, "INIT_VALUE") == 0) {
|
|
sscanf(value, "%f", &(config->init_value));
|
|
}
|
|
else if (strcmp(property, "THRESHOLD") == 0) {
|
|
sscanf(value, "%f", &(config->threshold));
|
|
}
|
|
else {
|
|
printf("Unknown property %s\n", property);
|
|
}
|
|
}
|
|
fclose(fp);
|
|
return 0;
|
|
}
|