Exemple #1
0
// send targeted jobs
//
bool send_targeted_jobs() {
    bool sent_something = false;
    if (config.debug_send) {
        log_messages.printf(MSG_NORMAL, "checking for targeted jobs\n");
    }
    sent_something |= send_jobs(ASSIGN_USER);
    sent_something |= send_jobs(ASSIGN_HOST);
    sent_something |= send_jobs(ASSIGN_TEAM);
    return sent_something;
}
Exemple #2
0
int mpi_main(int argc, char **argv,
             job_t (send_jobs)(filter_t *, unsigned char **, int, int),
             job_t (get_job)(filter_t *)) {
    int rank, image_width, image_height;
    filter_t filter;
    job_t job;
    double starttime;
    unsigned char ** result;

    MPI_Init(&argc, &argv);

    starttime = MPI_Wtime();
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    // Init
    if (rank == 0) {
        // Read in image and filter and send to workers
        if (argc < 3 || argc > 4) {
            fprintf(stderr, "USAGE: %s filter.txt input.pnm [output.pnm]\n",
                    argv[1]);
            return 1;
        }

        const char * filter_path = argv[1];
        const char * image_path  = argv[2];
        const char * output_path = argv[argc == 3 ? 2 : 3];

        unsigned char ** image;

        filter.filter = read_filter(filter_path, &filter.width, &filter.height);
        image = read_image(image_path, &image_width, &image_height);

        send_filter(&filter);
        job = send_jobs(&filter, image, image_width, image_height);

        result = do_job(&job, &filter);

        LOG("Fetching results.");
        fetch_results(result, image_width);

        LOG("Writing output");
        write_image(output_path, result, job.width, job.height);
    } else {
        // Receive filter and job
        filter = get_filter();
        job = get_job(&filter);

        result = do_job(&job, &filter);

        LOG("Sending results");
        send_result(&job, result);
    }

    // Cleanup
    /* free_filter(filter.filter, filter.height); */
    /* free_image(job.image); */
    /* free_image(result); */

    starttime = MPI_Wtime() - starttime;
    if (rank == 0)
        printf("%f\n", starttime);

    MPI_Finalize();

    return 0;
}