COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
fast_map.cpp
Go to the documentation of this file.
1/*
2//@HEADER
3// *****************************************************************************
4//
5// HPCGraph: Graph Computation on High Performance Computing Systems
6// Copyright (2016) Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact George M. Slota (gmslota@sandia.gov)
39// Siva Rajamanickam (srajama@sandia.gov)
40// Kamesh Madduri (madduri@cse.psu.edu)
41//
42// *****************************************************************************
43//@HEADER
44*/
45
46#include <mpi.h>
47#include <omp.h>
48#include <stdio.h>
49#include <stdlib.h>
50#include <stdint.h>
51
52#include "fast_map.h"
53#include "util.h"
54
55extern int procid, nprocs;
56extern bool verbose, debug, verify, output;
57
58bool is_init(fast_map* map)
59{
60 return (map->capacity > 0);
61}
62
64{
65 map->arr = NULL;
66 map->unique_keys = NULL;
67 map->unique_indexes = NULL;
68 map->capacity = 0;
69 map->num_unique = 0;
70}
71
72void init_map(fast_map* map, uint64_t init_size)
73{
74 map->arr = (uint64_t*)malloc(init_size*2*sizeof(uint64_t));
75 map->unique_keys = (uint64_t*)malloc(init_size*sizeof(uint64_t));
76 map->unique_indexes = (uint64_t*)malloc(init_size*sizeof(uint64_t));
77 if (map->arr == NULL || map->unique_keys == NULL ||
78 map->unique_indexes == NULL)
79 throw_err("init_map(), unable to allocate resources\n", procid);
80
81 map->capacity = init_size;
82 map->num_unique = 0;
83 map->hashing = true;
84
85#pragma omp parallel for
86 for (uint64_t i = 0; i < map->capacity; ++i)
87 map->arr[i*2] = NULL_KEY;
88}
89
90void init_map_nohash(fast_map* map, uint64_t init_size)
91{
92 map->arr = (uint64_t*)malloc(init_size*2*sizeof(uint64_t));
93 map->unique_keys = (uint64_t*)malloc(init_size*sizeof(uint64_t));
94 map->unique_indexes = (uint64_t*)malloc(init_size*sizeof(uint64_t));
95 if (map->arr == NULL || map->unique_keys == NULL ||
96 map->unique_indexes == NULL)
97 throw_err("init_map(), unable to allocate resources\n", procid);
98
99 map->capacity = init_size;
100 map->num_unique = init_size;
101 map->hashing = false;
102
103#pragma omp parallel
104{
105#pragma omp for nowait
106 for (uint64_t i = 0; i < map->capacity; ++i)
107 {
108 map->arr[2*i] = i;
109 map->arr[2*i+1] = i;
110 }
111#pragma omp for nowait
112 for (uint64_t i = 0; i < map->capacity; ++i)
113 map->unique_keys[i] = i;
114#pragma omp for nowait
115 for (uint64_t i = 0; i < map->capacity; ++i)
116 map->unique_indexes[i] = i;
117} // end parallel
118
119}
120
122{
123 free(map->arr);
124 free(map->unique_keys);
125 free(map->unique_indexes);
126
127 map->num_unique = 0;
128 map->capacity = 0;
129}
130
132{
133 for (uint64_t i = 0; i < map->num_unique; ++i)
134 map->arr[map->unique_indexes[i]] = NULL_KEY;
135
136 map->num_unique = 0;
137}
void clear_map(fast_map *map)
Definition fast_map.cpp:121
int procid
Definition main.cpp:55
void init_map_nohash(fast_map *map, uint64_t init_size)
Definition fast_map.cpp:90
bool debug
Definition fast_map.cpp:56
bool verify
Definition fast_map.cpp:56
void empty_map(fast_map *map)
Definition fast_map.cpp:131
bool is_init(fast_map *map)
Definition fast_map.cpp:58
bool verbose
Definition main.cpp:56
bool output
Definition fast_map.cpp:56
int nprocs
Definition fast_map.cpp:55
void init_map(fast_map *map)
Definition fast_map.cpp:63
#define NULL_KEY
Definition fast_map.h:58
unsigned __int64 uint64_t
Definition stdint.h:90
bool hashing
Definition fast_map.h:66
uint64_t * unique_keys
Definition fast_map.h:62
uint64_t num_unique
Definition fast_map.h:65
uint64_t capacity
Definition fast_map.h:64
uint64_t * unique_indexes
Definition fast_map.h:63
uint64_t * arr
Definition fast_map.h:61
void throw_err(char const *err_message)
Definition util.cpp:58