Program Structure

Download Pandemic-Serial.tgz

There are in total 8 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 CUDA functions in the file is not included in the file table, even though they are shown in the diagram. The initial serial program does not need these functions or the file. However, we will be using them later in a CUDA version of this code.

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


At the very beginning of the file, we need to include all the necessary code files. We first include file files that are needed with our without display.

#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"


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 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, &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(global.current_day = 0; global.current_day <= constant.total_number_of_days; 

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

        /****** In Infection.h ******/

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)

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



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

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

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

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

        update_days_infected(&global, &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(&global, &stats);

    cleanup(&global, &constant, &dpy);