GADGET-4
calc_checksum.cc
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#include "gadgetconfig.h"
13
14#ifdef DEBUG_MD5
15
16#include <mpi.h>
17#include <stdio.h>
18
19#include "../data/allvars.h"
20#include "../data/dtypes.h"
21#include "../debug_md5/Md5.h"
22#include "../logs/logs.h"
23#include "../main/simulation.h"
24
25void logs::block_checksum(void *base, size_t bytes, int res[4])
26{
27 MD5_CTX sum;
28 union
29 {
30 unsigned char digest[16];
31 int val[4];
32 } u;
33
34 MD5Init(&sum);
35 MD5UpdateLong(&sum, (unsigned char *)base, bytes);
36 MD5Final(&sum);
37
38 for(int i = 0; i < 16; i++)
39 u.digest[i] = sum.digest[i];
40
41 for(int i = 0; i < 4; i++)
42 res[i] = u.val[i];
43}
44
45void logs::calc_memory_checksum(const char *msg, void *base, size_t bytes)
46{
47 MD5_CTX sum;
48 union
49 {
50 unsigned char digest[16];
51 int val[4];
52 } u, uglob;
53
54 MD5Init(&sum);
55 MD5UpdateLong(&sum, (unsigned char *)base, bytes);
56 MD5Final(&sum);
57
58 for(int i = 0; i < 16; i++)
59 u.digest[i] = sum.digest[i];
60
61 MPI_Allreduce(u.val, uglob.val, 4, MPI_INT, MPI_SUM, Communicator);
62
63 if(ThisTask == 0)
64 {
65 fprintf(FdDebug, "\n");
66 fprintf(FdDebug, "Step=%8d P[] %s: ", All.NumCurrentTiStep, msg);
67 for(int i = 0; i < 16; i++)
68 fprintf(FdDebug, "%02x", uglob.digest[i]);
69 fprintf(FdDebug, "\n");
70 }
71}
72
73void logs::log_debug_md5(const char *msg)
74{
75 MD5_CTX sum;
76 union
77 {
78 unsigned char digest[16];
79 int val[4];
80 } u, uglob_P, uglob_SphP;
81
82 MD5Init(&sum);
83 MD5UpdateLong(&sum, (unsigned char *)Sp->P, Sp->NumPart * sizeof(particle_data));
84 MD5Final(&sum);
85
86 for(int i = 0; i < 16; i++)
87 u.digest[i] = sum.digest[i];
88
89 MPI_Allreduce(u.val, uglob_P.val, 4, MPI_INT, MPI_SUM, Communicator);
90
91 MD5Init(&sum);
92 MD5UpdateLong(&sum, (unsigned char *)Sp->SphP, Sp->NumGas * sizeof(sph_particle_data));
93 MD5Final(&sum);
94
95 for(int i = 0; i < 16; i++)
96 u.digest[i] = sum.digest[i];
97
98 MPI_Allreduce(u.val, uglob_SphP.val, 4, MPI_INT, MPI_SUM, Communicator);
99
100 if(ThisTask == 0)
101 {
102 fprintf(FdDebug, "\n");
103 fprintf(FdDebug, "Step=%8d P[] %s: ", All.NumCurrentTiStep, msg);
104 for(int i = 0; i < 16; i++)
105 fprintf(FdDebug, "%02x", uglob_P.digest[i]);
106 fprintf(FdDebug, "\n");
107
108 fprintf(FdDebug, " SphP[] %s: ", msg);
109 for(int i = 0; i < 16; i++)
110 fprintf(FdDebug, "%02x", uglob_SphP.digest[i]);
111 fprintf(FdDebug, "\n");
112
113 fflush(FdDebug);
114 }
115}
116
117#endif
void MD5UpdateLong(MD5_CTX *mdContext, unsigned char *inBuf, unsigned long long inLenLong)
void MD5Init(MD5_CTX *mdContext)
void MD5Final(MD5_CTX *mdContext)
global_data_all_processes All
Definition: main.cc:40
void block_checksum(void *base, size_t bytes, int res[4])
simparticles * Sp
Definition: logs.h:41
void calc_memory_checksum(const char *msg, void *base, size_t bytes)
void log_debug_md5(const char *msg)
int ThisTask
Definition: setcomm.h:33
MPI_Comm Communicator
Definition: setcomm.h:31
particle_data * P
Definition: simparticles.h:54
sph_particle_data * SphP
Definition: simparticles.h:59
Definition: Md5.h:51
unsigned char digest[16]
Definition: Md5.h:55