sstsimulator / sst-macro

SST Macro Element Library
http://sst-simulator.org/
Other
34 stars 41 forks source link

Algorithm implementation for MPI_Wtime? #628

Closed sunsirui closed 3 years ago

sunsirui commented 3 years ago

Dear All,

I have one question about the SST-Macro implementation of the MPI_Wtime In the following example, if the MPI_Wtime function is called twice in a row, the time obtained twice will be the same (unless other MPI functions are called in the middle, which will produce different times) Some questions:

  1. result of two consecutive calls to MPI_Wtime consistent. Is it correct?

DIM 25

static float *a; static float x; static float *y;

void allocate_host_arrays() {
int i=0, j=0; a = (float *)malloc(DIM sizeof(float *));

for (i = 0; i < DIM; i++) {
    a[i] = (float *)malloc(DIM * sizeof(float));
}

x = (float *)malloc(DIM * sizeof(float));
y = (float *)malloc(DIM * sizeof(float));

for (i = 0; i < DIM; i++) {
    x[i] = y[i] = 1.0f;
    for (j = 0; j < DIM; j++) {
        a[i][j] = 2.0f;
    }
}

}

void compute_on_host() { int i = 0, j = 0; for (i = 0; i < DIM; i++) for (j = 0; j < DIM; j++) x[i] = x[i] + a[i][j]*a[j][i] + y[j]; }

static inline void do_compute_cpu(double target_seconds) { double t1 = 0.0, t2 = 0.0; double time_elapsed = 0.0; while (time_elapsed < target_seconds) { t1 = MPI_Wtime(); compute_on_host(); t2 = MPI_Wtime(); time_elapsed += (t2-t1); // the time_elapsed always is zero } }

Thanks to anyone who may shed some light into this. -sirui

jpkenny commented 3 years ago

Hi Sirui,

This is expected behavior. Doing actual computation in a skeleton (such as in compute_on_host()) doesn't actually advance simulator time. Accounting for computation needs to be done explicitly. There are a number of ways to do this. The most straightforward examples would be sleep() and compute() in operating_system.h. We've been experimenting with more sophisticated compiler-based approaches, but the toolchain is pretty tricky to get working.

--Joe

jpkenny commented 3 years ago

This paper: https://www.osti.gov/servlets/purl/1513073

And Chapter 6 of the sst-macro manual talk about the source-to-source approach.

These are also good background reading for computation modeling in sst-macro.

--Joe

sunsirui commented 3 years ago

Hi jpkenny,

Thank you very much for your reply! I will use nanosleep() function in time.h, for I want to use a nano level time delay.

Thanks, --Sirui