Beispiel #1
0
//------//
// MAIN //
//------//
int main(int argc, const char *argv[])
{
    // SET DEFAULT VALUES AND INITIALIZE THE VARIABLES
    //------------------------------------------------
    Params p;
    p.cycle_num = 0;                // number of the current cycle of colonization tests
    p.time_eq = 0;                  // time step at which the equilibrium is reached (except when equal Tmax)
    p.nrep = 1;                     // number of replicates
    p.num = 1;                      // Number of the species
    p.ax[0] = 0.314;                // constantes for the per unit rate of metabolism for invertebrate predators
    p.ax[1] = 0.88;                 // constantes for the per unit rate of metabolism for ectothermes
    p.ay[0] = 8.0 * 0.314;          // constante for the per unit rate of maximum consumption for invertebrate predators
    p.ay[1] = 4.0 * 0.88;           // constante for the per unit rate of maximum consumption for ectothermes  
    p.Smax = 0;                     // maximal diversity during the assembly sequence
    p.stab = EAM_NOTHING;           // stability of the integration


    // USER INTERFACE
    //---------------
    int n_threads = 1;
    read_opt_i("t", argv, argc, &n_threads);
    p.nrep = n_threads;
    printf("Début de la simulation...\n");


    // CREATE THE THREADS
    //-------------------
    pthread_t threads[n_threads];
    int i = 0;
    for (; i < n_threads; ++i)
    {
        pthread_create(&threads[i], NULL, sim, (void*)&p);
    }

    // WAIT FOR THE THREADS TO END
    //----------------------------
    for (i = 0; i < n_threads; ++i)
    {
        pthread_join(threads[i], NULL);
    }
    printf("Finished!\n");
    return EXIT_SUCCESS;
}
Beispiel #2
0
Datei: main.c Projekt: PhDP/jsm
/////////////////////////////////////////////////////////////
// Main                                                    //
/////////////////////////////////////////////////////////////
int main(int argc, const char *argv[])
{
    // Set default values;
    Params p;
    p.kernel = gaussian_k;
    p.communities = 10;
    p.j_per_c = 10000;
    p.init_species = 20;
    p.k_gen = 100;
    p.mu = 1e-4;
    p.s = 0.15;
    p.var = 0.10;
    p.width = sqrt(2);
    p.eta = -8.0;
    p.ofilename = (char*)malloc(50);

    // Number of simulations;
    int n_threads = 1;

    // Options;
    if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-')
    {
        // --help
        if (argv[1][2] == 'h')
        {
            printf("Usage: ./origin [options]\n");
            printf("Example: ./origin -x=8 -shape=circle -model=1 -s=0.10\n");
            printf("General options:\n");
            printf("  --help          How you got here...\n");
            printf("  --version       Display version.\n");
            printf("  --ref           Display reference.\n");
            printf("Simulation parameters:\n");
            printf("  -x\n");
            printf("    description:  Number of simulations to run. Each simulation\n");
            printf("                  will use a distinct POSIX thread. \n");
            printf("    values:       Any unsigned integer.\n");
            printf("    default:      1\n");
            printf("  -k\n");
            printf("    description:  Dispersal kernel.\n");
            printf("    values:       0 for Gaussian, 1 for fat-tailed.\n");
            printf("    default:      0\n");
            printf("  -g\n");
            printf("    description:  Number of generations in thousands.\n");
            printf("    values:       Any positive integer.\n");
            printf("    default:      100 (i.e.: 100 000 generations)\n");
            printf("  -c\n");
            printf("    description:  Number of local communities.\n");
            printf("    values:       Any integer greater than 0.\n");
            printf("    default:      10\n");
            printf("  -jpc\n");
            printf("    description:  Number of individuals per communities.\n");
            printf("    values:       Any integer greater than 0.\n");
            printf("    default:      10000\n");
            printf("  -sp\n");
            printf("    description:  Initial number of species. Must be a factor\n");
            printf("                  of the number of individuals/community.\n");
            printf("    values:       Any positive integer greater than 0.\n");
            printf("    default:      20\n");
            printf("  -s\n");
            printf("    description:  Set the selection coefficient (model 1 only).\n");
            printf("    values:       Any double in the (-1.0, 1.0) interval.\n");
            printf("    default:      0.15\n");
            printf("  -v\n");
            printf("    description:  Set variance for gaussian kernel.\n");
            printf("    values:       Any positive double.\n");
            printf("    default:      0.10\n");
            printf("  -w\n");
            printf("    description:  The width of the fat-tailed kernel.\n");
            printf("    values:       Any positive double.\n");
            printf("    default:      sqrt(2)\n");
            printf("  -e\n");
            printf("    description:  Parameter eta of the fat-tailed kernel.\n");
            printf("    values:       Any negative values < -4.0.\n");
            printf("    default:      -8.0\n");
            printf("  -o\n");
            printf("    description:  Name of the output files.\n");
            printf("    values:       Any string.\n");
            return EXIT_SUCCESS;
        }
        else if (argv[1][2] == 'v') // --version
        { 
            printf("origin v.%d.%d (%s)\n", origin2_version, origin2_revision, origin2_date);
            printf("Copyright (c) 2012 Philippe Desjardins-Proulx <*****@*****.**>\n");
            printf("GPLv2 license  (see LICENSE)\n");
            return EXIT_SUCCESS;
        }
        else if (argv[1][2] == 'r') // --ref
        { 
            printf("P. Desjardins-Proul and D. Gravel. How likely is speciation in\n  neutral ecology? The American Naturalist 179(1).\n");
            return EXIT_SUCCESS;
        }
    } // end '--' options

    // Read options
    read_opt_i("g", argv, argc, &p.k_gen);
    read_opt_i("jpc", argv, argc, &p.j_per_c);
    read_opt_i("c", argv, argc, &p.communities);
    read_opt_i("sp", argv, argc, &p.init_species);
    read_opt_i("x", argv, argc, &n_threads);
    read_opt_i("k", argv, argc, &p.kernel);
    read_opt_d("mu", argv, argc, &p.mu);
    read_opt_d("v", argv, argc, &p.var);
    read_opt_d("w", argv, argc, &p.width);
    read_opt_d("e", argv, argc, &p.eta);
    read_opt_d("s", argv, argc, &p.s);
    if (read_opt_s("o", argv, argc, p.ofilename) == false)
    {
        sprintf(p.ofilename, "");
    }

    printf("<?xml version=\"1.0\"?>\n");
    printf("<origin2>\n");
    printf("  <version>%d</version>\n", origin2_version);
    printf("  <revision>%d</revision>\n", origin2_revision);
    if (p.kernel == gaussian_k)
    {
        printf("  <model>Gaussian</model>\n");
    }
    else
    {
        printf("  <model>Fat-tailed</model>\n");
    }
    printf("  <n>%d</n>\n", n_threads);
    printf("  <metacom_size>%d</metacom_size>\n", p.j_per_c * p.communities);
    printf("  <k_gen>%d</k_gen>\n", p.k_gen);
    printf("  <num_comm>%d</num_comm>\n", p.communities);
    printf("  <individuals_per_comm>%d</individuals_per_comm>\n", p.j_per_c);
    printf("  <initial_num_species>%d</initial_num_species>\n", p.init_species);
    printf("  <mutation_rate>%.2e</mutation_rate>\n", p.mu);
    if (p.kernel == gaussian_k)
    {
        printf("  <variance>%.8e</variance>\n", p.var);
    }
    else
    {
        printf("  <width>%.8e</width>\n", p.width);
        printf("  <eta>%.8e</eta>\n", p.eta);
    }
    printf("  <selection>%.2e</selection>\n", p.s);
    printf("  <filename>%s</filename>\n", p.ofilename);

    // The threads:
    pthread_t threads[n_threads];

    const time_t start = time(NULL);

    // Create the threads:
    for (int i = 0; i < n_threads; ++i)
    {
        pthread_create(&threads[i], NULL, sim, (void*)&p);
    }

    // Wait for the threads to end:
    for (int i = 0; i < n_threads; ++i)
    {
        pthread_join(threads[i], NULL);
    }

    const time_t end_t = time(NULL);
    printf("  <seconds>%lu</seconds>\n", (unsigned long)(end_t - start));
    printf("  <time>%s</time>\n", sec_to_string(end_t - start));
    printf("</origin2>\n");
    return EXIT_SUCCESS; // yeppie !
}
Beispiel #3
0
/////////////////////////////////////////////////////////////
// Main                                                    //
/////////////////////////////////////////////////////////////
int main(int argc, const char *argv[])
{
    // Set default values;
    Params p;
    p.m = MODEL_BDM_SELECTION;
    p.communities = 10;
    p.j_per_c = 10000;
    p.init_species = 20;
    p.k_gen = 100;
    p.mu = 1e-4;
    p.omega = 5e-4;
    p.s = 0.15;
    p.r = 0.25;
    p.w = 0.25;
    p.ofilename = (char*)malloc(50);
    p.shape = (char*)malloc(20);

    // Number of simulations;
    int n_threads = 1;

    // Options;
    if (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-')
    {
        // --help
        if (argv[1][2] == 'h')
        {
            printf("Usage: ./origin [options]\n");
            printf("Example: ./origin -x=8 -shape=circle -model=1 -s=0.10\n");
            printf("General options:\n");
            printf("  --help          How you got here...\n");
            printf("  --version       Display version.\n");
            printf("  --ref           Display reference.\n");
            printf("Simulation parameters:\n");
            printf("  -x\n");
            printf("    description:  Number of simulations to run. Each simulation\n");
            printf("                  will use a distinct POSIX thread. \n");
            printf("    values:       Any unsigned integer.\n");
            printf("    default:      1\n");
            printf("  -model\n");
            printf("    description:  Set the model used.\n");
            printf("    values:       0, 1.\n");
            printf("    details:      0 = Neutral BDM speciation.\n");
            printf("                  1 = BDM speciation with selection.\n");
            printf("    default:      1\n");
            printf("  -shape\n");
            printf("    description:  Set the shape of the metacommunity.\n");
            printf("    values:       circle, complete, random, rectangle, star.\n");
            printf("    default:      random\n");
            printf("  -r\n");
            printf("    description:  Threshold radius for random geometric\n");
            printf("                  graphs.\n");
            printf("    values:       Any double greater than 0.\n");
            printf("    default:      0.25\n");
            printf("  -w\n");
            printf("    description:  The width of a rectangle random geometric\n");
            printf("                  graph.\n");
            printf("    values:       0 < w < 1\n");
            printf("    default:      0.25\n");
            printf("  -g\n");
            printf("    description:  Number of generations in thousands.\n");
            printf("    values:       Any positive integer.\n");
            printf("    default:      100 (i.e.: 100 000 generations)\n");
            printf("  -c\n");
            printf("    description:  Number of local communities.\n");
            printf("    values:       Any integer greater than 0.\n");
            printf("    default:      10\n");
            printf("  -jpc\n");
            printf("    description:  Number of individuals per communities.\n");
            printf("    values:       Any integer greater than 0.\n");
            printf("    default:      10000\n");
            printf("  -sp\n");
            printf("    description:  Initial number of species. Must be a factor\n");
            printf("                  of the number of individuals/community.\n");
            printf("    values:       Any positive integer greater than 0.\n");
            printf("    default:      20\n");
            printf("  -s\n");
            printf("    description:  Set the selection coefficient (model 1 only).\n");
            printf("    values:       Any double in the (-1.0, 1.0) interval.\n");
            printf("    default:      0.15\n");
            printf("  -mu\n");
            printf("    description:  Set the mutation rate.\n");
            printf("    values:       Any positive double.\n");
            printf("    default:      1e-4\n");
            printf("  -omega\n");
            printf("    description:  The weight of the proper edges.\n");
            printf("    values:       Any nonnegative double.\n");
            printf("    default:      5e-4\n");
            printf("  -o\n");
            printf("    description:  Name of the output files.\n");
            printf("    values:       Any string.\n");
            return EXIT_SUCCESS;
        }
        else if (argv[1][2] == 'v') // --version
        { 
            printf("origin v.%s (%s)\n", ORIGIN_VERSION, ORIGIN_DATE);
            printf("Copyright (c) 2010-2011 Philippe Desjardins-Proulx <*****@*****.**>\n");
            printf("GPLv2 license  (see LICENSE)\n");
            return EXIT_SUCCESS;
        }
        else if (argv[1][2] == 'r') // --ref
        { 
            printf("P. Desjardins-Proul and D. Gravel. How likely is speciation in\n  neutral ecology? The American Naturalist 179(1).\n");
            return EXIT_SUCCESS;
        }
    } // end '--' options

    // Read options
    read_opt_i("g", argv, argc, &p.k_gen);
    read_opt_i("jpc", argv, argc, &p.j_per_c);
    read_opt_i("model", argv, argc, &p.m);
    read_opt_i("c", argv, argc, &p.communities);
    read_opt_i("sp", argv, argc, &p.init_species);
    read_opt_i("x", argv, argc, &n_threads);
    read_opt_d("mu", argv, argc, &p.mu);
    read_opt_d("omega", argv, argc, &p.omega);
    read_opt_d("r", argv, argc, &p.r);
    read_opt_d("w", argv, argc, &p.w);
    read_opt_d("s", argv, argc, &p.s);
    if (read_opt_s("o", argv, argc, p.ofilename) == false)
    {
        sprintf(p.ofilename, "");
    }
    if (read_opt_s("shape", argv, argc, p.shape) == false)
    {
        sprintf(p.shape, "random");
    }

    printf("<?xml version=\"1.0\"?>\n");
    printf("<origin_ssne>\n");
    printf("  <model>");
    if (p.m == MODEL_BDM_NEUTRAL)
    {
        printf("Neutral BDM speciation</model>\n");
    }
    else if (p.m == MODEL_BDM_SELECTION)
    {
        printf("BDM speciation with selection</model>\n");
    }
    printf("  <n>%d</n>\n", n_threads);
    printf("  <shape_metacom>%s</shape_metacom>\n", p.shape);
    printf("  <metacom_size>%d</metacom_size>\n", p.j_per_c * p.communities);
    printf("  <k_gen>%d</k_gen>\n", p.k_gen);
    printf("  <num_comm>%d</num_comm>\n", p.communities);
    printf("  <individuals_per_comm>%d</individuals_per_comm>\n", p.j_per_c);
    printf("  <initial_num_species>%d</initial_num_species>\n", p.init_species);
    printf("  <mutation_rate>%.2e</mutation_rate>\n", p.mu);
    printf("  <omega>%.2e</omega>\n", p.omega);
    if (p.m == MODEL_BDM_SELECTION)
    {
        printf("  <selection>%.2e</selection>\n", p.s);
    }
    if (p.shape[0] == 'r')
    {
        printf("  <radius>%.4f</radius>\n", p.r);
    }
    if (p.shape[0] == 'r' && p.shape[1] == 'e')
    {
        printf("  <width>%.4f</width>\n", p.w);
    }
    printf("  <filename>%s</filename>\n", p.ofilename);

    // The threads:
    pthread_t threads[n_threads];

    const time_t start = time(NULL);

    // Create the threads:
    for (int i = 0; i < n_threads; ++i)
    {
        pthread_create(&threads[i], NULL, sim, (void*)&p);
    }

    // Wait for the threads to end:
    for (int i = 0; i < n_threads; ++i)
    {
        pthread_join(threads[i], NULL);
    }

    const time_t end_t = time(NULL);
    printf("  <seconds>%lu</seconds>\n", (unsigned long)(end_t - start));
    printf("  <time>%s</time>\n", sec_to_string(end_t - start));
    printf("</origin_ssne>\n");
    return EXIT_SUCCESS; // yeppie !
}