Display Functions

init_display

Rank 0 initializes the graphics display. The code uses X to handle graphics display.

share_location

If display is enabled, Rank 0 gathers the states, x locations, and y locations of the people for which each process is responsible

image

We set up the displs here just as we did in function share_infected().

    // Distributed Memory Information
    int *recvcounts;
    int *displs;
    recvcounts = (int*)malloc(total_number_of_processes * sizeof(int));  
    displs = (int*)malloc(total_number_of_processes * sizeof(int));

    // Set up the receive counts and displacements in the 
    // receive buffer (see the man page for MPI_Gatherv)
    int current_displ = 0;
    int current_rank;
    for(current_rank = 0; current_rank <= total_number_of_processes - 1;
       current_rank++)
    {
        displs[current_rank] = current_displ;
        recvcounts[current_rank] = total_number_of_people / total_number_of_processes;
        if(current_rank == global->total_number_of_processes - 1)
        {
            recvcounts[current_rank] += total_number_of_people
            % total_number_of_processes;
        }
        current_displ += recvcounts[current_rank];
    }

Three calls to Gatherv take place for each process to send each of their our_states, our_x_locations, and our_y_locations arrays. Rank 0 copies these into its states, x_locations, and y_locations arrays, respectively.

    MPI_Gatherv(our->our_states, our->our_number_of_people, MPI_CHAR, 
        global->states, recvcounts, displs, MPI_CHAR, 0, MPI_COMM_WORLD);
    MPI_Gatherv(our->our_x_locations, our->our_number_of_people, MPI_INT, 
        global->x_locations, recvcounts, displs, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Gatherv(our->our_y_locations, our->our_number_of_people, MPI_INT, 
        global->y_locations, recvcounts, displs, MPI_INT, 0, MPI_COMM_WORLD);

Note that if MPI is not enabled, Rank 0 just does a direct copy of the arrays without using Gatherv.

    int my_current_person_id;
    for(my_current_person_id = 0; my_current_person_id 
       <= global->total_number_of_people - 1; my_current_person_id++)
    {
       global->states[my_current_person_id] 
       = our->our_states[my_current_person_id];
       global->x_locations[my_current_person_id] 
       = our->our_x_locations[my_current_person_id];
       global->y_locations[my_current_person_id] 
       = our->our_y_locations[my_current_person_id];
    }
    #endif
}

do_display

If display is enabled, Rank 0 displays a graphic of the current day

image

close_display

If X display is enabled, then Rank 0 destroys the X Window and closes the display

throttle

In order for better display, we wait between frames of animation.