Program Structure

Download Pandemic-MPI.zip

There are in total 7 files in this program.

File Name Functions
Pandemic.c Holds All the function calls
Defaults.h Data structure and default values
Initialize.h Initialize the runtime environment
Infection.h Find and share all infected persons
Display.h Display everyone’s state and location
Core.h Use serial or OpenMP for core operations
Finalize.h Finalize the run time environment

Program Structure

alternate text

Overall Program Structurer

The rest of the module will go through each of the code files. We can start with the Pandemic.c file.

Pandemic.c

At the very beginning of the file, We first include four files that are needed for all versions.

#include "Defaults.h"
#include "Initialize.h"
#include "Infection.h"
#include "Core.h"
#include "Finalize.h"

Then, if we are using display, we include the display code file.

#if defined(X_DISPLAY) || defined(TEXT_DISPLAY)
#include "Display.h"
#endif

main()

This function is the backbone of the whole program. It first initialize all the data structures need.

    /**** In Defaults.h ****/
    struct global_t global;
    struct our_t our;
    struct const_t constant;
    struct stats_t stats;
    struct display_t dpy;
    /***********************/

Then it will initialize the runtime environment by calling init() function.

    /******************** In Initialize.h ********************/
    init(&global, &our, &constant, &stats, &dpy, &argc, &argv);
    /*********************************************************/

Then we start the simulation. A for loop wraps around most of the functions, where the each iteration of the loop represents a day passing.

    for(our.current_day = 0; our.current_day <= constant.total_number_of_days; 
        our.current_day++)
    {
    }

Inside the for loop, we first find all data related to the infection.

       /****** In Infection.h ******/
        find_infected(&our);

        share_infected(&global, &our);
        /****************************/

Then, if display is enabled, we display the infection status. In other words, we display everyone’s location and their states of infection.

        /**************** In Display.h *****************/
        #if defined(X_DISPLAY) || defined(TEXT_DISPLAY)

        share_display_info(&global, &our);

        do_display(&global, &our, &constant, &dpy);

        throttle(&constant);
        
        #endif
        /***********************************************/

After display, we can call four core functions in Core.h* code file.

        /******************* In Core.h ******************/
        move(&our, &constant);      

        susceptible(&global, &our, &constant, &stats);

        infected(&our, &constant, &stats);

        update_days_infected(&our, &constant);
        /************************************************/

This is the end of the loop.

Finally, after the loop, we can display the results and finalize the runtime environment.

    /**************** In Finialize.h **************/
    show_results(&our, &stats);

    cleanup(&global, &our, &constant, &dpy);
    /**********************************************/