forked from yecol/xtrapulp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast_map.cpp
120 lines (103 loc) · 4.13 KB
/
fast_map.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
//@HEADER
// *****************************************************************************
//
// XtraPuLP: Xtreme-Scale Graph Partitioning using Label Propagation
// Copyright (2016) Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact George M. Slota ([email protected])
// Siva Rajamanickam ([email protected])
// Kamesh Madduri ([email protected])
//
// *****************************************************************************
//@HEADER
*/
#include <mpi.h>
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "fast_map.h"
#include "util.h"
namespace pulp{
extern int procid, nprocs;
extern bool verbose, debug, verify;
void init_map(fast_map* map, uint64_t init_size)
{
if (debug) { printf("Task %d init_map() start\n", procid); }
map->arr = (uint64_t*)malloc(init_size*2*sizeof(uint64_t));
map->unique_keys = (uint64_t*)malloc(init_size*sizeof(uint64_t));
map->unique_indexes = (uint64_t*)malloc(init_size*sizeof(uint64_t));
if (map->arr == NULL || map->unique_keys == NULL ||
map->unique_indexes == NULL)
throw_err("init_map(), unable to allocate resources\n", procid);
map->capacity = init_size;
map->num_unique = 0;
map->hashing = true;
#pragma omp parallel for
for (uint64_t i = 0; i < map->capacity; ++i)
map->arr[i*2] = NULL_KEY;
if (debug) { printf("Task %d init_map() success\n", procid); }
}
void init_map_nohash(fast_map* map, uint64_t init_size)
{
if (debug) { printf("Task %d init_map_nohash() start\n", procid); }
map->arr = (uint64_t*)malloc(init_size*2*sizeof(uint64_t));
map->unique_keys = (uint64_t*)malloc(init_size*sizeof(uint64_t));
map->unique_indexes = (uint64_t*)malloc(init_size*sizeof(uint64_t));
if (map->arr == NULL || map->unique_keys == NULL ||
map->unique_indexes == NULL)
throw_err("init_map(), unable to allocate resources\n", procid);
map->capacity = init_size;
map->num_unique = 0;
map->hashing = false;
#pragma omp parallel for
for (uint64_t i = 0; i < map->capacity; ++i)
map->arr[i*2] = NULL_KEY;
if (debug) { printf("Task %d init_map_nohash() success\n", procid); }
}
void clear_map(fast_map* map)
{
free(map->arr);
free(map->unique_keys);
free(map->unique_indexes);
map->num_unique = 0;
map->capacity = 0;
}
void empty_map(fast_map* map)
{
for (uint64_t i = 0; i < map->num_unique; ++i)
map->arr[map->unique_indexes[i]] = NULL_KEY;
map->num_unique = 0;
}
}