FasTensor  1.0.0
Transform Supercomputing for AI
ft_utility_macro.h
Go to the documentation of this file.
1 /*
2 ****************************
3 
4 FasTensor (FT) Copyright (c) 2021, The Regents of the University of
5 California, through Lawrence Berkeley National Laboratory (subject to
6 receipt of any required approvals from the U.S. Dept. of Energy).
7 All rights reserved.
8 
9 If you have questions about your rights to use or distribute this software,
10 please contact Berkeley Lab's Intellectual Property Office at
12 
13 NOTICE. This Software was developed under funding from the U.S. Department
14 of Energy and the U.S. Government consequently retains certain rights. As
15 such, the U.S. Government has been granted for itself and others acting on
16 its behalf a paid-up, nonexclusive, irrevocable, worldwide license in the
17 Software to reproduce, distribute copies to the public, prepare derivative
18 works, and perform publicly and display publicly, and to permit others to do so.
19 
20 
21 ****************************
22 
23 
24 *** License Agreement ***
25 
26 FasTensor (FT) Copyright (c) 2021, The Regents of the University of
27 California, through Lawrence Berkeley National Laboratory (subject to
28 receipt of any required approvals from the U.S. Dept. of Energy).
29 All rights reserved.
30 
31 Redistribution and use in source and binary forms, with or without
32 modification, are permitted provided that the following conditions are met:
33 
34 (1) Redistributions of source code must retain the above copyright notice,
35 this list of conditions and the following disclaimer.
36 
37 (2) Redistributions in binary form must reproduce the above copyright
38 notice, this list of conditions and the following disclaimer in the
39 documentation and/or other materials provided with the distribution.
40 
41 (3) Neither the name of the University of California, Lawrence Berkeley
42 National Laboratory, U.S. Dept. of Energy nor the names of its contributors
43 may be used to endorse or promote products derived from this software
44 without specific prior written permission.
45 
46 
47 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
48 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
51 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
52 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
53 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
54 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
55 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 POSSIBILITY OF SUCH DAMAGE.
58 
59 You are under no obligation whatsoever to provide any bug fixes, patches,
60 or upgrades to the features, functionality or performance of the source
61 code ("Enhancements") to anyone; however, if you choose to make your
62 Enhancements available either publicly, or directly to Lawrence Berkeley
63 National Laboratory, without imposing a separate written license agreement
64 for such Enhancements, then you hereby grant the following license: a
65 non-exclusive, royalty-free perpetual license to install, use, modify,
66 prepare derivative works, incorporate into other computer software,
67 distribute, and sublicense such enhancements or derivative works thereof,
68 in binary and source code form.
69 */
70 
80 #ifndef ARRAY_UDF_UTILITY_MACRO_H
81 #define ARRAY_UDF_UTILITY_MACRO_H
82 
83 extern int ft_mpi_size_global;
84 extern int ft_mpi_rank_global;
85 extern int ft_size;
86 extern int ft_rank;
87 
92 #define COUNT_CELLS(start_address_p, end_address_p, cells_count_p) \
93  { \
94  assert(start_address_p.size() == end_address_p.size()); \
95  cells_count_p = 1; \
96  for (int i = 0; i < start_address_p.size(); i++) \
97  { \
98  cells_count_p = cells_count_p * (end_address_p[i] - start_address_p[i] + 1); \
99  } \
100  }
101 
106 #define COUNT_RANGES(start_address_p, end_address_p, count_p) \
107  { \
108  assert(start_address_p.size() == end_address_p.size()); \
109  if (count_p.size() != start_address_p.size()) \
110  { \
111  count_p.resize(start_address_p.size()); \
112  } \
113  for (int i = 0; i < start_address_p.size(); i++) \
114  { \
115  count_p[i] = end_address_p[i] - start_address_p[i] + 1; \
116  } \
117  }
118 
123 #ifndef ROW_MAJOR_ORDER_MACRO
124 #define ROW_MAJOR_ORDER_MACRO(dsize, dsize_len, coordinate, offset) \
125  { \
126  offset = coordinate[0]; \
127  for (int iii = 1; iii < dsize_len; iii++) \
128  { \
129  offset = offset * dsize[iii] + coordinate[iii]; \
130  } \
131  }
132 #endif
133 
134 #ifndef ROW_MAJOR_ORDER_REVERSE_MACRO
135 #define ROW_MAJOR_ORDER_REVERSE_MACRO(offset, dsize, dsize_len, result_coord_v) \
136  { \
137  unsigned long long temp_offset = offset; \
138  for (int iii = dsize_len - 1; iii >= 1; iii--) \
139  { \
140  result_coord_v[iii] = temp_offset % dsize[iii]; \
141  temp_offset = temp_offset / dsize[iii]; \
142  } \
143  result_coord_v[0] = temp_offset; \
144  }
145 #endif
146 
147 #define AU_EXIT(info) \
148  { \
149  std::cout << "Exit happens at file: " << __FILE__ << ", function: " << __func__ << ", line: " << __LINE__ << std::endl; \
150  std::cout << "Log : " << info << std::endl; \
151  std::exit(EXIT_FAILURE); \
152  }
153 
154 #define AU_INFO(info) \
155  { \
156  std::cout << "Info at " << __FILE__ << ", " << __func__ << ", " << __LINE__ << std::endl; \
157  std::cout << "Info : " << info << std::endl; \
158  }
159 #define AU_VERBOSE(info_p, rank_p) \
160  { \
161  if (ft_rank == rank_p) \
162  std::cout << info_p << std::endl \
163  << std::flush; \
164  }
165 #endif
int ft_rank
Definition: ft.cpp:86
int ft_mpi_size_global
Definition: ft.cpp:82
int ft_size
Definition: ft.cpp:85
int ft_mpi_rank_global
Definition: ft.cpp:83