COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
comms.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 "comms.h"
53#include "util.h"
54
55extern int procid, nprocs;
56extern bool verbose, debug, verify, output;
57
59{
60 if (debug) { printf("Task %d init_queue_data() start\n", procid); }
61
62 uint64_t queue_size = g->m_local_in + g->m_local_out;
63 q->queue = (uint64_t*)malloc(queue_size*sizeof(uint64_t));
64 q->queue_next = (uint64_t*)malloc(queue_size*sizeof(uint64_t));
65 q->queue_send = (uint64_t*)malloc(queue_size*sizeof(uint64_t));
66 if (q->queue == NULL || q->queue_next == NULL || q->queue_send == NULL)
67 throw_err("init_queue_data(), unable to allocate resources\n", procid);
68
69 q->queue_size = 0;
70 q->next_size = 0;
71 q->send_size = 0;
72 if (debug) { printf("Task %d init_queue_data() success\n", procid); }
73}
74
76{
77 if (debug) { printf("Task %d clear_queque_data() start\n", procid); }
78 free(q->queue);
79 free(q->queue_next);
80 free(q->queue_send);
81 if (debug) { printf("Task %d clear_queque_data() success\n", procid); }
82}
83
85{
86 if (debug) { printf("Task %d init_comm_data() start\n", procid); }
87
88 comm->sendcounts = (int32_t*)malloc(nprocs*sizeof(int32_t));
89 comm->sendcounts_temp = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
90 comm->recvcounts = (int32_t*)malloc(nprocs*sizeof(int32_t));
91 comm->recvcounts_temp = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
92 comm->sdispls = (int32_t*)malloc(nprocs*sizeof(int32_t));
93 comm->rdispls = (int32_t*)malloc(nprocs*sizeof(int32_t));
94 comm->rdispls_temp = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
95 comm->sdispls_cpy = (int32_t*)malloc(nprocs*sizeof(int32_t));
96 comm->sdispls_temp = (uint64_t*)malloc(nprocs*sizeof(int64_t));
97 comm->sdispls_cpy_temp = (uint64_t*)malloc(nprocs*sizeof(int64_t));
98
99 if (comm->sendcounts == NULL || comm->sendcounts_temp == NULL ||
100 comm->recvcounts == NULL || comm->sdispls == NULL ||
101 comm->rdispls == NULL || comm->rdispls_temp == NULL ||
102 comm->sdispls_cpy == NULL || comm->sdispls_cpy_temp == NULL)
103 throw_err("init_comm_data(), unable to allocate resources\n", procid);
104
105 comm->total_recv = 0;
106 comm->total_send = 0;
107 comm->global_queue_size = 0;
108 if (debug) { printf("Task %d init_comm_data() success\n", procid); }
109}
110
112{
113 if (debug) { printf("Task %d clear_comm_data() start\n", procid); }
114 free(comm->sendcounts);
115 free(comm->sendcounts_temp);
116 free(comm->recvcounts);
117 free(comm->recvcounts_temp);
118 free(comm->sdispls);
119 free(comm->rdispls);
120 free(comm->sdispls_cpy);
121 free(comm->sdispls_temp);
122 if (debug) { printf("Task %d clear_comm_data() success\n", procid); }
123}
124
126{
127 if (debug) { printf("Task %d clear_thread_queue_comm_data() start\n", procid); }
128 free(comm->sendcounts);
129 free(comm->recvcounts);
130 free(comm->sdispls);
131 free(comm->rdispls);
132 free(comm->sdispls_cpy);
133 if (debug) { printf("Task %d clear_thread_queue_comm_data() success\n", procid); }
134}
135
137{
138 tq->tid = omp_get_thread_num();
139 if (debug) {
140 printf("Task %d Thread %d init_thread_queue() start\n", procid, tq->tid);
141 }
142
143 tq->thread_queue = (uint64_t*)malloc(THREAD_QUEUE_SIZE*sizeof(uint64_t));
144 tq->thread_send = (uint64_t*)malloc(THREAD_QUEUE_SIZE*sizeof(uint64_t));
145 if (tq->thread_queue == NULL || tq->thread_send == NULL)
146 throw_err("init_thread_queue(), unable to allocate resources\n", procid, tq->tid);
147
148 tq->tid = omp_get_thread_num();
149 tq->thread_queue_size = 0;
150 tq->thread_send_size = 0;
151 if (debug) {
152 printf("Task %d Thread %d init_thread_queue() success\n", procid, tq->tid);
153 }
154
155}
156
158{
159 if (debug) {
160 printf("Task %d Thread %d clear_thread_queue() start\n", procid, tq->tid);
161 }
162 free(tq->thread_queue);
163 free(tq->thread_send);
164 if (debug) {
165 printf("Task %d Thread %d clear_thread_queue() success\n", procid, tq->tid);
166 }
167}
168
170{
171 tc->tid = omp_get_thread_num();
172 if (debug) {
173 printf("Task %d Thread %d init_thread_comm() start\n", procid, tc->tid);
174 }
175
176 tc->v_to_rank = (bool*)malloc(nprocs*sizeof(bool));
177 tc->sendcounts_thread = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
179 (uint64_t*)malloc(THREAD_QUEUE_SIZE*sizeof(uint64_t));
181 (uint64_t*)malloc(THREAD_QUEUE_SIZE*sizeof(uint64_t));
183 tc->thread_starts = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
184 if (tc->v_to_rank == NULL || tc->sendcounts_thread == NULL ||
185 tc->sendbuf_vert_thread == NULL || tc->sendbuf_data_thread == NULL ||
186 tc->sendbuf_rank_thread == NULL || tc->thread_starts == NULL)
187 throw_err("init_thread_comm(), unable to allocate resources\n", procid, tc->tid);
188
189 for (int32_t i = 0; i < nprocs; ++i)
190 tc->sendcounts_thread[i] = 0;
191
192 tc->thread_queue_size = 0;
193
194 if (debug) {
195 printf("Task %d Thread %d init_thread_comm() success\n", procid, tc->tid);
196 }
197}
198
200{
201 free(tc->v_to_rank);
202 free(tc->sendcounts_thread);
203 free(tc->sendbuf_vert_thread);
204 free(tc->sendbuf_data_thread);
205 free(tc->sendbuf_rank_thread);
206 free(tc->thread_starts);
207}
208
210{
211 tc->tid = omp_get_thread_num();
212 if (debug) {
213 printf("Task %d Thread %d init_thread_comm_flt() start\n", procid, tc->tid);
214 }
215
216 tc->v_to_rank = (bool*)malloc(nprocs*sizeof(bool));
217 tc->sendcounts_thread = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
219 (uint64_t*)malloc(THREAD_QUEUE_SIZE*sizeof(uint64_t));
220 tc->sendbuf_data_thread = NULL;
222 (double*)malloc(THREAD_QUEUE_SIZE*sizeof(double));
224 tc->thread_starts = (uint64_t*)malloc(nprocs*sizeof(uint64_t));
225 if (tc->v_to_rank == NULL || tc->sendcounts_thread == NULL ||
226 tc->sendbuf_vert_thread == NULL || tc->sendbuf_data_thread_flt == NULL ||
227 tc->sendbuf_rank_thread == NULL || tc->thread_starts == NULL)
228 throw_err("init_thread_comm(), unable to allocate resources\n", procid, tc->tid);
229
230 tc->thread_queue_size = 0;
231
232 for (int32_t i = 0; i < nprocs; ++i)
233 tc->sendcounts_thread[i] = 0;
234
235 if (debug) {
236 printf("Task %d Thread %d init_thread_comm_flt() success\n", procid, tc->tid);
237 }
238}
239
241{
242 free(tc->v_to_rank);
243 free(tc->sendcounts_thread);
244 free(tc->sendbuf_vert_thread);
245 free(tc->sendbuf_data_thread);
246 free(tc->sendbuf_rank_thread);
247 free(tc->thread_starts);
248}
249
250
252{
253 if (debug) { printf("Task %d init_sendbuf_vid_data() start\n", procid); }
254
255 comm->sdispls_temp[0] = 0;
256 comm->sdispls_cpy_temp[0] = 0;
257 for (int32_t i = 1; i < nprocs; ++i)
258 {
259 comm->sdispls_temp[i] = comm->sdispls_temp[i-1] + comm->sendcounts_temp[i-1];
260 comm->sdispls_cpy_temp[i] = comm->sdispls_temp[i];
261 }
262
263 comm->total_send = comm->sdispls_temp[nprocs-1] + comm->sendcounts_temp[nprocs-1];
264 comm->sendbuf_vert = (uint64_t*)malloc(comm->total_send*sizeof(uint64_t));
265 comm->sendbuf_data = (uint64_t*)malloc(comm->total_send*sizeof(uint64_t));
266 comm->sendbuf_data_flt = NULL;
267 if (comm->sendbuf_vert == NULL || comm->sendbuf_data == NULL)
268 throw_err("init_sendbuf_vid_data(), unable to allocate resources\n", procid);
269
270 comm->global_queue_size = 0;
271 uint64_t task_queue_size = comm->total_send;
272 MPI_Allreduce(&task_queue_size, &comm->global_queue_size, 1,
273 MPI_UINT64_T, MPI_SUM, MPI_COMM_WORLD);
274
275 if (debug) { printf("Task %d init_sendbuf_vid_data() success\n", procid); }
276}
277
279{
280 if (debug) { printf("Task %d init_recvbuf_vid_data() start\n", procid); }
281
282 for (int32_t i = 0; i < nprocs; ++i)
283 comm->recvcounts_temp[i] = 0;
284
285 MPI_Alltoall(comm->sendcounts_temp, 1, MPI_UINT64_T,
286 comm->recvcounts_temp, 1, MPI_UINT64_T, MPI_COMM_WORLD);
287
288 comm->rdispls_temp[0] = 0;
289
290 for (int i = 1; i < nprocs; ++i)
291 {
292 comm->rdispls_temp[i] = comm->rdispls_temp[i-1] + comm->recvcounts_temp[i-1];
293 }
294
295 comm->total_recv = comm->rdispls_temp[nprocs-1] + comm->recvcounts_temp[nprocs-1];
296 comm->recvbuf_vert = (uint64_t*)malloc(comm->total_recv*sizeof(uint64_t));
297 comm->recvbuf_data = (uint64_t*)malloc(comm->total_recv*sizeof(uint64_t));
298 comm->recvbuf_data_flt = NULL;
299 if (comm->recvbuf_vert == NULL || comm->recvbuf_data == NULL)
300 throw_err("init_recvbuf_vid_data() unable to allocate comm buffers", procid);
301
302 if (debug) { printf("Task %d init_recvbuf_vid_data() success\n", procid); }
303}
304
306{
307 if (debug) { printf("Task %d init_sendbuf_vid_data_flt() start\n", procid); }
308
309 comm->sdispls_temp[0] = 0;
310 comm->sdispls_cpy_temp[0] = 0;
311 for (int32_t i = 1; i < nprocs; ++i)
312 {
313 comm->sdispls_temp[i] = comm->sdispls_temp[i-1] + comm->sendcounts_temp[i-1];
314 comm->sdispls_cpy_temp[i] = comm->sdispls_temp[i];
315 }
316
317 comm->total_send = comm->sdispls_temp[nprocs-1] + comm->sendcounts_temp[nprocs-1];
318 comm->sendbuf_vert = (uint64_t*)malloc(comm->total_send*sizeof(uint64_t));
319 comm->sendbuf_data = NULL;
320 comm->sendbuf_data_flt = (double*)malloc(comm->total_send*sizeof(double));
321 if (comm->sendbuf_vert == NULL || comm->sendbuf_data_flt == NULL)
322 throw_err("init_sendbuf_vid_data_flt(), unable to allocate resources\n", procid);
323
324 comm->global_queue_size = 0;
325 uint64_t task_queue_size = comm->total_send;
326 MPI_Allreduce(&task_queue_size, &comm->global_queue_size, 1,
327 MPI_UINT64_T, MPI_SUM, MPI_COMM_WORLD);
328
329 if (debug) { printf("Task %d init_sendbuf_vid_data_flt() success\n", procid); }
330}
331
333{
334 if (debug) { printf("Task %d init_recvbuf_vid_data_flt() start\n", procid); }
335
336 for (int32_t i = 0; i < nprocs; ++i)
337 comm->recvcounts_temp[i] = 0;
338
339 MPI_Alltoall(comm->sendcounts_temp, 1, MPI_UINT64_T,
340 comm->recvcounts_temp, 1, MPI_UINT64_T, MPI_COMM_WORLD);
341
342 comm->rdispls_temp[0] = 0;
343
344 for (int i = 1; i < nprocs; ++i)
345 {
346 comm->rdispls_temp[i] = comm->rdispls_temp[i-1] + comm->recvcounts_temp[i-1];
347 }
348
349 comm->total_recv = comm->rdispls_temp[nprocs-1] + comm->recvcounts_temp[nprocs-1];
350 comm->recvbuf_vert = (uint64_t*)malloc(comm->total_recv*sizeof(uint64_t));
351 comm->recvbuf_data = NULL;
352 comm->recvbuf_data_flt = (double*)malloc(comm->total_recv*sizeof(double));
353 if (comm->recvbuf_vert == NULL || comm->recvbuf_data_flt == NULL)
354 throw_err("init_recvbuf_vid_data_flt() unable to allocate comm buffers", procid);
355
356 if (debug) { printf("Task %d init_recvbuf_vid_data_flt() success\n", procid); }
357}
358
360{
361 free(comm->recvbuf_vert);
362 free(comm->recvbuf_data);
363
364 for (int32_t i = 0; i < nprocs; ++i)
365 comm->sendcounts[i] = 0;
366 for (int32_t i = 0; i < nprocs; ++i)
367 comm->sendcounts_temp[i] = 0;
368}
369
371{
372 free(comm->sendbuf_vert);
373 free(comm->recvbuf_vert);
374
375 if (comm->sendbuf_data != NULL)
376 free(comm->sendbuf_data);
377 if (comm->recvbuf_data != NULL)
378 free(comm->recvbuf_data);
379 if (comm->sendbuf_data_flt != NULL)
380 free(comm->sendbuf_data_flt);
381 if (comm->recvbuf_data_flt != NULL)
382 free(comm->recvbuf_data_flt);
383
384 for (int32_t i = 0; i < nprocs; ++i)
385 comm->sendcounts[i] = 0;
386 for (int32_t i = 0; i < nprocs; ++i)
387 comm->sendcounts_temp[i] = 0;
388}
Mac OS X ATTR com apple quarantine q
Definition ._remapper.cpp:1
void clear_comm_data(mpi_data_t *comm)
Definition comms.cpp:111
void clear_recvbuf_vid_data(mpi_data_t *comm)
Definition comms.cpp:359
int procid
Definition main.cpp:55
bool debug
Definition comms.cpp:56
void init_thread_comm(thread_comm_t *tc)
Definition comms.cpp:169
void clear_queue_data(queue_data_t *q)
Definition comms.cpp:75
void init_thread_queue(thread_queue_t *tq)
Definition comms.cpp:136
void init_recvbuf_vid_data(mpi_data_t *comm)
Definition comms.cpp:278
bool verify
Definition comms.cpp:56
void init_sendbuf_vid_data_flt(mpi_data_t *comm)
Definition comms.cpp:305
void init_thread_comm_flt(thread_comm_t *tc)
Definition comms.cpp:209
void init_recvbuf_vid_data_flt(mpi_data_t *comm)
Definition comms.cpp:332
void clear_thread_queue(thread_queue_t *tq)
Definition comms.cpp:157
void init_queue_data(dist_graph_t *g, queue_data_t *q)
Definition comms.cpp:58
bool verbose
Definition main.cpp:56
void clear_thread_queue_comm_data(mpi_data_t *comm)
Definition comms.cpp:125
bool output
Definition comms.cpp:56
int nprocs
Definition comms.cpp:55
void init_sendbuf_vid_data(mpi_data_t *comm)
Definition comms.cpp:251
void clear_thread_comm_flt(thread_comm_t *tc)
Definition comms.cpp:240
void clear_allbuf_vid_data(mpi_data_t *comm)
Definition comms.cpp:370
void init_comm_data(mpi_data_t *comm)
Definition comms.cpp:84
void clear_thread_comm(thread_comm_t *tc)
Definition comms.cpp:199
#define THREAD_QUEUE_SIZE
Definition comms.h:63
long int64_t
Definition compat.h:21
signed int int32_t
Definition stdint.h:77
unsigned __int64 uint64_t
Definition stdint.h:90
uint64_t m_local_in
Definition dist_graph.h:64
uint64_t m_local_out
Definition dist_graph.h:63
uint64_t * sdispls_temp
Definition comms.h:74
uint64_t * sendbuf_data
Definition comms.h:79
uint64_t * sendcounts_temp
Definition comms.h:73
int32_t * sendcounts
Definition comms.h:66
uint64_t total_send
Definition comms.h:86
double * sendbuf_data_flt
Definition comms.h:80
uint64_t * recvbuf_data
Definition comms.h:82
uint64_t * sendbuf_vert
Definition comms.h:78
uint64_t total_recv
Definition comms.h:85
int32_t * sdispls
Definition comms.h:68
uint64_t * recvcounts_temp
Definition comms.h:72
int32_t * rdispls
Definition comms.h:69
int32_t * recvcounts
Definition comms.h:67
uint64_t * sdispls_cpy_temp
Definition comms.h:76
uint64_t global_queue_size
Definition comms.h:87
double * recvbuf_data_flt
Definition comms.h:83
uint64_t * recvbuf_vert
Definition comms.h:81
int32_t * sdispls_cpy
Definition comms.h:70
uint64_t * rdispls_temp
Definition comms.h:75
bool * v_to_rank
Definition comms.h:110
uint64_t * thread_starts
Definition comms.h:116
double * sendbuf_data_thread_flt
Definition comms.h:114
uint64_t * sendbuf_vert_thread
Definition comms.h:112
uint64_t thread_queue_size
Definition comms.h:117
uint64_t * sendbuf_data_thread
Definition comms.h:113
int32_t * sendbuf_rank_thread
Definition comms.h:115
int32_t tid
Definition comms.h:109
uint64_t * sendcounts_thread
Definition comms.h:111
uint64_t thread_queue_size
Definition comms.h:104
uint64_t * thread_send
Definition comms.h:103
uint64_t thread_send_size
Definition comms.h:105
uint64_t * thread_queue
Definition comms.h:102
int32_t tid
Definition comms.h:101
void throw_err(char const *err_message)
Definition util.cpp:58