Skip to content
Snippets Groups Projects
Commit f3f691d8 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Don't overflow when converting to bytes and switch to subtype/rank/size as key

parent 67b2ea44
No related branches found
No related tags found
1 merge request!8Draft: RDMA version with wrapped infinity calls
...@@ -90,6 +90,9 @@ static const int task_type_recv = 23; ...@@ -90,6 +90,9 @@ static const int task_type_recv = 23;
/* Bit shift to accomodate all the bits of the maximum rank id. */ /* Bit shift to accomodate all the bits of the maximum rank id. */
static int rank_shift = 0; static int rank_shift = 0;
/* Bit shift to accomodate all the bits of the maximum subtype. */
static int subtype_shift = 0;
/* Maximum no. of messages (logs). */ /* Maximum no. of messages (logs). */
static size_t max_logs = 0; static size_t max_logs = 0;
...@@ -113,18 +116,18 @@ static struct mpiuse_log_entry **volatile recvs_queue[MAX_NR_RANKS]; ...@@ -113,18 +116,18 @@ static struct mpiuse_log_entry **volatile recvs_queue[MAX_NR_RANKS];
static int volatile starting[MAX_NR_RANKS] = {1}; static int volatile starting[MAX_NR_RANKS] = {1};
/** /**
* @brief Convert two ranks and tag into a single unique value. * @brief Convert a rank, subtype and tag into a single unique value.
* *
* Assumes there is enough space in a size_t for these values. * Assumes there is enough space in a size_t for these values.
* *
* @param sendrank the send rank XXX currently the subtype... XXX * @param subtype the subtype of the message
* @param recvrank the receive rank * @param recvrank the receive rank
* @param tag the tag * @param tag the tag
* *
* @result a unique value based on both values * @result a unique value based on both values
*/ */
static size_t toranktag(int sendrank, int recvrank, int tag) { static size_t toranktag(int subtype, int recvrank, int tag) {
size_t result = sendrank | recvrank << rank_shift | tag << (rank_shift * 2); size_t result = subtype | recvrank << subtype_shift | tag << (rank_shift * 2);
return result; return result;
} }
...@@ -164,7 +167,7 @@ static BLOCKTYPE toblocks(BLOCKTYPE nr_bytes) { ...@@ -164,7 +167,7 @@ static BLOCKTYPE toblocks(BLOCKTYPE nr_bytes) {
* *
* @result the number of bytes. * @result the number of bytes.
*/ */
static BLOCKTYPE tobytes(int nr_blocks) { return (nr_blocks * BYTESINBLOCK); } static BLOCKTYPE tobytes(BLOCKTYPE nr_blocks) { return (nr_blocks * BYTESINBLOCK); }
/** /**
* @brief fill a data area with given value. * @brief fill a data area with given value.
...@@ -364,14 +367,12 @@ static void *recv_thread(void *arg) { ...@@ -364,14 +367,12 @@ static void *recv_thread(void *arg) {
auto *context = new infinity::core::Context(); auto *context = new infinity::core::Context();
auto *qpFactory = new infinity::queues::QueuePairFactory(context); auto *qpFactory = new infinity::queues::QueuePairFactory(context);
/* Buffer to receive all the remote data. XXX mystery factor of 2.*/ /* Buffer to receive all the remote data.*/
auto *bufferToReadWrite = auto *bufferToReadWrite =
new infinity::memory::Buffer(context, 2 * tobytes(ranktag_sizes[rank])); new infinity::memory::Buffer(context, tobytes(ranktag_sizes[rank]));
infinity::memory::RegionToken *bufferToken = infinity::memory::RegionToken *bufferToken =
bufferToReadWrite->createRegionToken(); bufferToReadWrite->createRegionToken();
// XXX need to make sure it is initialised. XXX
// Port binding. // Port binding.
if (verbose) { if (verbose) {
message("%d binding to %d on port %d", myrank, rank, BASE_PORT + rank); message("%d binding to %d on port %d", myrank, rank, BASE_PORT + rank);
...@@ -574,8 +575,7 @@ static size_t pick_logs() { ...@@ -574,8 +575,7 @@ static size_t pick_logs() {
/* Setup the ranktag offsets for our receive windows. Also define the sizes /* Setup the ranktag offsets for our receive windows. Also define the sizes
* of the windows. XXX note these are over the complete lists not the * of the windows. XXX note these are over the complete lists not the
* separated ones, k != index of sub queues. * separated ones, k != index of sub queues. */
* XXX need to also include subtype in ranktag XXX */
for (int k = 0; k < nr_recv; k++) { for (int k = 0; k < nr_recv; k++) {
struct mpiuse_log_entry *log = recv_queue[k]; struct mpiuse_log_entry *log = recv_queue[k];
ranktag_lists[INDEX3(MAX_NR_RANKS, nr_ranks, log->otherrank, log->rank, ranktag_lists[INDEX3(MAX_NR_RANKS, nr_ranks, log->otherrank, log->rank,
...@@ -668,9 +668,10 @@ int main(int argc, char *argv[]) { ...@@ -668,9 +668,10 @@ int main(int argc, char *argv[]) {
error("The number of MPI ranks %d does not match the expected value %d", error("The number of MPI ranks %d does not match the expected value %d",
nranks, nr_ranks); nranks, nr_ranks);
/* Index of most significant bit in the maximum rank id. Assumes GCC /* Index of most significant bits in the maximum rank and subtypes.
* intrinsic. */ * Assumes GCC intrinsic. */
rank_shift = (sizeof(int) * CHAR_BIT) - __builtin_clz(nr_ranks); rank_shift = (sizeof(int) * CHAR_BIT) - __builtin_clz(nr_ranks);
subtype_shift = (sizeof(int) * CHAR_BIT) - __builtin_clz(32);
/* We all need to agree on a maximum count of logs, so we can exchange the /* We all need to agree on a maximum count of logs, so we can exchange the
* offset arrays (would be ragged otherwise and difficult to exchange). */ * offset arrays (would be ragged otherwise and difficult to exchange). */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment