mirror of
https://github.com/cp2k/cp2k.git
synced 2026-07-29 06:35:28 -04:00
Replace clock_gettime() with omp_get_wtime()
This commit is contained in:
parent
3d29584519
commit
88f495e73f
2 changed files with 14 additions and 33 deletions
|
|
@ -5,31 +5,18 @@
|
|||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
// needed for struct timespec
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <assert.h>
|
||||
#include <omp.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../offload/offload_library.h"
|
||||
#include "dbm_library.h"
|
||||
#include "dbm_matrix.h"
|
||||
#include "dbm_mpi.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* \brief Private routine for subtracting two timespecs.
|
||||
* \author Ole Schuett
|
||||
******************************************************************************/
|
||||
static double time_diff(const struct timespec start,
|
||||
const struct timespec end) {
|
||||
return (end.tv_sec - start.tv_sec) + 1e-9 * (end.tv_nsec - start.tv_nsec);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* \brief Private routine for creating a distribution and an empty matrix.
|
||||
* \author Ole Schuett
|
||||
|
|
@ -144,16 +131,16 @@ int main(int argc, char *argv[]) {
|
|||
dbm_library_init();
|
||||
|
||||
// Benchmark reserve blocks.
|
||||
struct timespec time_start, time_end;
|
||||
clock_gettime(CLOCK_REALTIME, &time_start);
|
||||
const double time_start_reserve = omp_get_wtime();
|
||||
for (int icycle = 0; icycle < 50; icycle++) {
|
||||
dbm_matrix_t *matrix = create_some_matrix(comm);
|
||||
reserve_all_blocks(matrix);
|
||||
dbm_release(matrix);
|
||||
}
|
||||
clock_gettime(CLOCK_REALTIME, &time_end);
|
||||
const double time_end_reserve = omp_get_wtime();
|
||||
if (my_rank == 0) {
|
||||
printf("reserve blocks: %.3f seconds\n", time_diff(time_start, time_end));
|
||||
const double t = time_end_reserve - time_start_reserve;
|
||||
printf("reserve blocks: %.3f seconds\n", t);
|
||||
}
|
||||
|
||||
// Benchmark matrix multiply.
|
||||
|
|
@ -165,16 +152,16 @@ int main(int argc, char *argv[]) {
|
|||
set_all_blocks(matrix_a);
|
||||
set_all_blocks(matrix_b);
|
||||
int64_t flop;
|
||||
clock_gettime(CLOCK_REALTIME, &time_start);
|
||||
const double time_start_multiply = omp_get_wtime();
|
||||
dbm_multiply(false, false, 1.0, matrix_a, matrix_b, 1.0, matrix_c, false,
|
||||
1e-8, &flop);
|
||||
clock_gettime(CLOCK_REALTIME, &time_end);
|
||||
const double time_end_multiply = omp_get_wtime();
|
||||
dbm_release(matrix_a);
|
||||
dbm_release(matrix_b);
|
||||
dbm_release(matrix_c);
|
||||
|
||||
const double t = time_diff(time_start, time_end);
|
||||
if (my_rank == 0) {
|
||||
const double t = time_end_multiply - time_start_multiply;
|
||||
printf("matrix multiply: %.3f s, %.1f MFLOP/s \n", t, 1e-6 * flop / t);
|
||||
printf("done :-)\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,19 +5,16 @@
|
|||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
// needed for struct timespec
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <assert.h>
|
||||
#include <fenv.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <omp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../offload/offload_buffer.h"
|
||||
#include "common/grid_common.h"
|
||||
|
|
@ -333,8 +330,7 @@ double grid_replay(const char *filename, const int cycles, const bool collocate,
|
|||
double hab_test[n2][n1];
|
||||
double forces_test[2][3];
|
||||
double virial_test[3][3];
|
||||
|
||||
struct timespec start_time, end_time;
|
||||
double start_time, end_time;
|
||||
|
||||
if (batch) {
|
||||
grid_basis_set *basisa = NULL, *basisb = NULL;
|
||||
|
|
@ -356,7 +352,7 @@ double grid_replay(const char *filename, const int cycles, const bool collocate,
|
|||
pab_blocks->host_buffer[j * n1 + i] = 0.5 * f * pab[j][i];
|
||||
}
|
||||
}
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
|
||||
start_time = omp_get_wtime();
|
||||
const int nlevels = 1;
|
||||
const int natoms = 2;
|
||||
if (collocate) {
|
||||
|
|
@ -376,14 +372,14 @@ double grid_replay(const char *filename, const int cycles, const bool collocate,
|
|||
}
|
||||
}
|
||||
}
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
|
||||
end_time = omp_get_wtime();
|
||||
grid_free_basis_set(basisa);
|
||||
grid_free_basis_set(basisb);
|
||||
grid_free_task_list(task_list);
|
||||
offload_free_buffer(pab_blocks);
|
||||
offload_free_buffer(hab_blocks);
|
||||
} else {
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
|
||||
start_time = omp_get_wtime();
|
||||
if (collocate) {
|
||||
// collocate
|
||||
memset(grid_test->host_buffer, 0, npts_local_total * sizeof(double));
|
||||
|
|
@ -413,10 +409,8 @@ double grid_replay(const char *filename, const int cycles, const bool collocate,
|
|||
}
|
||||
}
|
||||
}
|
||||
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
|
||||
end_time = omp_get_wtime();
|
||||
}
|
||||
const double delta_sec = (end_time.tv_sec - start_time.tv_sec) +
|
||||
1e-9 * (end_time.tv_nsec - start_time.tv_nsec);
|
||||
|
||||
double max_value = 0.0;
|
||||
double max_rel_diff = 0.0;
|
||||
|
|
@ -483,7 +477,7 @@ double grid_replay(const char *filename, const int cycles, const bool collocate,
|
|||
"Max rel diff: %le Time: %le sec\n",
|
||||
filename, collocate ? "Collocate" : "Integrate",
|
||||
batch ? "Batched" : "PGF-Ref", (float)cycles, max_value, max_rel_diff,
|
||||
delta_sec);
|
||||
end_time - start_time);
|
||||
|
||||
offload_free_buffer(grid_ref);
|
||||
offload_free_buffer(grid_test);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue