GADGET-4
sums_and_minmax.cc
Go to the documentation of this file.
1/*******************************************************************************
2 * \copyright This file is part of the GADGET4 N-body/SPH code developed
3 * \copyright by Volker Springel. Copyright (C) 2014-2020 by Volker Springel
4 * \copyright (vspringel@mpa-garching.mpg.de) and all contributing authors.
5 *******************************************************************************/
6
12#include "gadgetconfig.h"
13
14#include <math.h>
15#include <mpi.h>
16#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include "../data/allvars.h"
21#include "../data/dtypes.h"
22#include "../data/mymalloc.h"
23#include "../mpi_utils/mpi_utils.h"
24
25void minimum_large_ints(int n, long long *src, long long *res, MPI_Comm comm)
26{
27 if(src == res)
28 MPI_Allreduce(MPI_IN_PLACE, res, n, MPI_LONG_LONG, MPI_MIN, comm);
29 else
30 MPI_Allreduce(src, res, n, MPI_LONG_LONG, MPI_MIN, comm);
31}
32
33void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
34{
35 long long *numlist = (long long *)Mem.mymalloc("numlist", n * sizeof(long long));
36
37 for(int j = 0; j < n; j++)
38 numlist[j] = src[j];
39 MPI_Allreduce(numlist, res, n, MPI_LONG_LONG, MPI_SUM, comm);
40
41 Mem.myfree(numlist);
42}
43
44void sumup_longs(int n, long long *src, long long *res, MPI_Comm comm)
45{
46 if(src == res)
47 MPI_Allreduce(MPI_IN_PLACE, res, n, MPI_LONG_LONG, MPI_SUM, comm);
48 else
49 MPI_Allreduce(src, res, n, MPI_LONG_LONG, MPI_SUM, comm);
50}
memory Mem
Definition: main.cc:44
void sumup_large_ints(int n, int *src, long long *res, MPI_Comm comm)
void minimum_large_ints(int n, long long *src, long long *res, MPI_Comm comm)
void sumup_longs(int n, long long *src, long long *res, MPI_Comm comm)