-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgda_dpointer.c
More file actions
94 lines (77 loc) · 2.67 KB
/
Copy pathgda_dpointer.c
File metadata and controls
94 lines (77 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2023 ETH Zurich.
// All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// main author: Robert Gerstenberger
/**
Inspired by the original DPointer implementation of Emanuel Peter,
which was written for the bachelor thesis:
Towards a High-Performance Distributed In-Memory RMA Graph Database
by Emanuel Peter
*/
#include <stdio.h>
#include "gda_dpointer.h"
#include "rma.h" /* equal to #include <mpi.h> */
/**
A DPointer consists of two fields: rank and offset, where each
field occupies a certain amount of bits.
* The rank can be found in the higher order bits of a dpointer.
* The offset can be found in the lower order bits of a dpointer.
--------------------------------
| rank | offset |
--------------------------------
The number of bits used for the offset is controlled by the
constant GDA_DPOINTER_OFFSETBITS. The number of bits used for the
rank is 64 - GDA_DPOINTER_OFFSETBITS.
*/
/**
both input parameter are 64 bit integer to allow for a different
amount of offset bits
*/
// TODO: Make this function static inline?
void GDA_SetDPointer(uint64_t offset, uint64_t rank, GDA_DPointer* dpointer) {
#ifndef NDEBUG
uint64_t rank_upper_bound = (uint64_t)1 << (64 - GDA_DPOINTER_OFFSETBITS);
uint64_t offset_upper_bound = (uint64_t)1 << GDA_DPOINTER_OFFSETBITS;
if( rank >= rank_upper_bound ) {
fprintf( stderr, "GDA_SetDPointer: rank parameter (%" PRIu64 ") is outside its bounds.\n", rank);
MPI_Abort( MPI_COMM_WORLD, -1 );
}
if( offset >= offset_upper_bound ) {
fprintf( stderr, "GDA_SetDPointer: offset parameter (%" PRIu64 ") is outside its bounds.\n", offset);
MPI_Abort( MPI_COMM_WORLD, -1 );
}
#endif /* #ifndef NDEBUG */
*dpointer = (rank << GDA_DPOINTER_OFFSETBITS) | offset;
}
// TODO: Make this function static inline?
void GDA_GetDPointer(uint64_t* offset, uint64_t* rank, GDA_DPointer dpointer) {
/**
remove the block offset field first
*/
*rank = dpointer >> GDA_DPOINTER_OFFSETBITS;
/**
remove the rank field first
*/
*offset = (dpointer << (64 - GDA_DPOINTER_OFFSETBITS)) >> (64 - GDA_DPOINTER_OFFSETBITS);
}
bool GDA_DPointerIsNull(GDA_DPointer dpointer) {
return dpointer == GDA_DPOINTER_NULL;
}
void GDA_PrintDPointer(GDA_DPointer dpointer) {
uint64_t rank, offset;
if( GDA_DPointerIsNull( dpointer ) ) {
/**
DPointer is NULL
*/
printf("DPointer: NULL\n");
} else {
/**
DPointer is valid.
*/
GDA_GetDPointer( &offset, &rank, dpointer );
printf("DPointer: rank = %" PRIu64 ", offset = %" PRIu64 "\n", rank, offset);
}
}