mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-12-25 22:03:57 +01:00
63 lines
2.0 KiB
Plaintext
63 lines
2.0 KiB
Plaintext
|
#include <assert.h>
|
||
|
#include <stdint.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
static __inline__ uint64_t rdtsc(void) {
|
||
|
unsigned hi, lo;
|
||
|
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
|
||
|
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
|
||
|
}
|
||
|
|
||
|
int qmckl_sherman_morrison(
|
||
|
const uint64_t LDS, const uint64_t Dim, const uint64_t N_updates,
|
||
|
const double *__restrict __attribute__((aligned(8))) Updates,
|
||
|
const uint64_t *__restrict Updates_index, const double breakdown,
|
||
|
double *__restrict __attribute__((aligned(8))) Slater_inv,
|
||
|
double *__restrict determinant);
|
||
|
|
||
|
int detupd(const uint64_t LDS, const uint64_t Dim, const uint64_t N_updates,
|
||
|
const double *__restrict __attribute__((aligned(8))) Updates,
|
||
|
const uint64_t *__restrict Updates_index, const double breakdown,
|
||
|
double *__restrict __attribute__((aligned(8))) Slater_inv,
|
||
|
double *__restrict determinant);
|
||
|
|
||
|
#define REPETITIONS 100000000
|
||
|
int main(int argc, char **argv) {
|
||
|
|
||
|
assert(argc == 2);
|
||
|
char *version = argv[1];
|
||
|
|
||
|
const uint64_t Dim = 21;
|
||
|
const uint64_t LDS = 24;
|
||
|
const uint64_t N_updates = 1;
|
||
|
double Updates[LDS] __attribute__((aligned(8)));
|
||
|
uint64_t Updates_index[N_updates];
|
||
|
Updates_index[0] = 1;
|
||
|
const double breakdown = 1e-3;
|
||
|
double Slater_inv[LDS * Dim] __attribute__((aligned(8)));
|
||
|
double determinant = 1.0;
|
||
|
|
||
|
for (int i = 0; i < Dim; i++) {
|
||
|
Updates[i] = i;
|
||
|
for (int j = 0; j < Dim; j++) {
|
||
|
Slater_inv[LDS * i + j] = j;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
uint64_t before = rdtsc();
|
||
|
if (version[0] == 'c') {
|
||
|
for (int i = 0; i < REPETITIONS; i++) {
|
||
|
detupd(LDS, Dim, N_updates, Updates, Updates_index, breakdown, Slater_inv,
|
||
|
&determinant);
|
||
|
}
|
||
|
} else {
|
||
|
for (int i = 0; i < REPETITIONS; i++) {
|
||
|
qmckl_sherman_morrison(LDS, Dim, N_updates, Updates, Updates_index,
|
||
|
breakdown, Slater_inv, &determinant);
|
||
|
}
|
||
|
}
|
||
|
uint64_t after = rdtsc();
|
||
|
printf("cycles = %f\n", ((double)(after - before) / (double)REPETITIONS));
|
||
|
}
|