Beispiel #1
0
static AM_ErrorCode_t cfg_parse (AM_CFG_Parser_t *parser)
{
	int end = 0;
	
	do
	{
		AM_TRY(cfg_read_line(parser, &end));
	}
	while(!end);
	
	return AM_SUCCESS;
}
Beispiel #2
0
int cfg_read(Config cfg, FILE* f) {
    int err = 0;
    char line[CFG_MAX_LINE_LENGTH];
    if(f == NULL) {
        fprintf(stderr, "cfg_read: file pointer is NULL\n");
        return CFG_STREAM_ERROR;
    }
    while(fgets(line, sizeof(line), f) != NULL) {
        err = cfg_read_line(cfg, line);
        if(err)
            break;
    }
    return err;
}
Beispiel #3
0
int main(int argc, char* argv[]) {
    int nprocs, myid, root;
    int Ncells, Nmodes;
    Cell* cells;

    Config cfg = cfg_new();

    /* Initialize MPI */
    MPI_Init(&argc, &argv);
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Comm_size(comm, &nprocs);
    MPI_Comm_rank(comm, &myid);
    root = nprocs - 1;

    /* Parse command line switches */
    int opt;
    const char* optstring = "hc:";
    while((opt = getopt(argc, argv, optstring)) != -1) {
        switch(opt) {
        case 'h':
            print_usage(stdout, argv[0]);
            return 0;
        case 'c':
            cfg_read_file(cfg, optarg);
            break;
        default:
            print_usage(stderr, argv[0]);
            MPI_Abort(comm, 1);
        }
    }

    /* Parse additional command line options */
    for(int i = optind; i < argc; i++)
        cfg_read_line(cfg, argv[i]);

    /* Debugging... */
    if(myid == root) {
        printf("# Config options\n");
        cfg_write(cfg, stdout);
    }

    if(myid == 0) {
        printf("Testing malloc...\n");
        char* test = (char*) malloc(72000*sizeof(char));
        if(test == NULL) {
            fprintf(stderr, "Could not allocate a measly 72000 bytes!\n");
            perror("system error:");
        }
        free(test);
    }

    /* Make sure all the necessary options are provided */
    if(!cfg_has_keys(cfg, "cellfile,specfile", ",")) {
        print_usage(stderr, argv[0]);
        MPI_Abort(comm, 1);
    }
    const char* cellfile = cfg_get(cfg, "cellfile");
    const char* specfile = cfg_get(cfg, "specfile");

    /* Read cells from file */
    if(myid == 0) printf("Reading cells from '%s' ...\n", cellfile);
    cells = ReadCells(comm, cellfile, Ncells);
    if(cells == NULL) {
        if(myid == 0) fprintf(stderr, "Failed to read cells.\n");
        if(myid == 0) perror("system error");
        MPI_Abort(comm, 1);
    }
    else {
        if(myid == 0) printf("Read %d cells.\n", Ncells);
        if(myid == 0) printf("  cells[0] = { %d, %d, %g, %g, %g, %g, %g, %g, %g, %g }\n", cells[0].a, cells[0].G, cells[0].rmin, cells[0].rmax, cells[0].mumin, cells[0].mumax, cells[0].phimin, cells[0].phimax, cells[0].Veff, cells[0].Nbar);
    }

    /* Read KL mode coefficients */
    Matrix B;   // cell -> KL mode projection matrix
    Matrix C;   // full covariance matrix in KL basis (diagonal)
    if(myid == 0) printf("Reading KL spectrum from '%s' ...\n", specfile);
    if(ReadSpectrum(comm, specfile, Nmodes, Ncells, B, C) != 0) {
        if(myid == 0) fprintf(stderr, "Failed to read spectrum.\n");
        if(myid == 0) perror("system error");
        MPI_Abort(comm, 1);
    }
    else {
        if(myid == 0) printf("Read spectrum: Nmodes = %d, Ncells = %d\n", Nmodes, Ncells);
    }

    /* Clean up nicely */
    free(cells);
    MPI_Finalize();

    return 0;
}