Xmipp  v3.23.11-Nereus
reconstruct_fourier_util.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jan Polak (456647@mail.muni.cz)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef XMIPP_LIBRARIES_RECONSTRUCT_FOURIER_UTIL_H_
27 #define XMIPP_LIBRARIES_RECONSTRUCT_FOURIER_UTIL_H_
28 
29 #include <cstdint>
30 
36 const uint32_t ALIGNMENT = 32;
37 
38 inline uint32_t alignmentOf(size_t ptr) {
39  uintptr_t p = (uintptr_t) ptr;
40  uint32_t alignment = 1;
41  while (true) {
42  uint32_t nextAlignment = alignment << 1;
43  if (nextAlignment == 0)
44  break;
45  if ((p & nextAlignment) != 0)
46  return nextAlignment;
47  alignment = nextAlignment;
48  }
49  return alignment;
50 }
51 
52 inline uint32_t alignmentOf(void * ptr) {
53  return alignmentOf((size_t) ptr);
54 }
55 
56 template<typename T>
57 inline T align(T number, uint32_t alignment) {
58  T off = number % alignment;
59  if (off == 0) {
60  return number;
61  } else {
62  return number + alignment - off;
63  }
64 }
65 
67 #define CHECK_STARPU(operationWithReturnCode) do {\
68  int check_result = (operationWithReturnCode);\
69  STARPU_CHECK_RETURN_VALUE(check_result, #operationWithReturnCode);\
70 } while (0)
71 
73 #define CHECK_MPI(operationWithReturnCode) do {\
74  int check_result = (operationWithReturnCode);\
75  if (STARPU_UNLIKELY(check_result != 0)) {\
76  fprintf(stderr, "Unexpected value: <%d> returned for %s\n", check_result, #operationWithReturnCode);\
77  fprintf(stderr, "[abort][%s:%d]\n", __FILE__, __LINE__);\
78  STARPU_DUMP_BACKTRACE(); _starpu_abort();\
79  }}while(0)
80 
81 
82 #endif //XMIPP_LIBRARIES_RECONSTRUCT_FOURIER_UTIL_H_
uint32_t alignmentOf(size_t ptr)
const uint32_t ALIGNMENT
T align(T number, uint32_t alignment)