-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.r
189 lines (133 loc) · 4.19 KB
/
grid.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#' grid class
#'
#' Storage and methods for MPI grid data.
#'
#' @details
#' Data is held in an external pointer.
#'
#' @rdname mpi-grid-class
#' @name mpi-grid-class
gridR6 = R6::R6Class("grid",
public = list(
#' @details
#' Class initializer.
#' @param gridtype Type of processor grid: \code{PROC_GRID_SQUARE},
#' \code{PROC_GRID_WIDE}, or \code{PROC_GRID_TALL}.
#' @useDynLib fmlr R_grid_init
initialize = function(gridtype=PROC_GRID_SQUARE)
{
gridtype = as.integer(gridtype)
private$g_ptr = .Call(R_grid_init, gridtype)
},
#' @details
#' Set grid to another BLACS context.
#' @param blacs_context The BLACS integer context number.
#' @useDynLib fmlr R_grid_set
set = function(blacs_context)
{
blacs_context = as.integer(blacs_context)
.Call(R_grid_set, private$g_ptr, blacs_context)
invisible(self)
},
#' @details
#' Exits the BLACS grid, but does not shutdown BLACS/MPI.
#' @useDynLib fmlr R_grid_exit
exit = function()
{
.Call(R_grid_exit, private$g_ptr)
invisible(self)
},
#' @details
#' Shuts down BLACS, and optionally MPI.
#' @param mpi_continue Should MPI continue, i.e., not be shut down too?
#' @useDynLib fmlr R_grid_finalize
finalize = function(mpi_continue=FALSE)
{
mpi_continue = as.logical(mpi_continue)
.Call(R_grid_finalize, private$g_ptr, mpi_continue)
invisible(self)
},
#' @details
#' Print one-line information about the object.
#' @useDynLib fmlr R_grid_info
info = function()
{
.Call(R_grid_info, private$g_ptr)
invisible(self)
},
#' @details
#' Print one-line information about the object.
print = function()
{
.Call(R_grid_info, private$g_ptr)
invisible(self)
},
#' @details
#' Is the calling process rank 0, i.e. row 0 and col 0?
#' @useDynLib fmlr R_grid_rank0
rank0 = function() .Call(R_grid_rank0, private$g_ptr),
#' @details
#' Is the calling process in the grid, i.e. row and col not -1?
#' @useDynLib fmlr R_grid_ingrid
ingrid = function() .Call(R_grid_ingrid, private$g_ptr),
#' @details
#' Execute a barrier.
#' @param scope 'A' for all, 'R' for row, or 'C' for column.
#' @useDynLib fmlr R_grid_barrier
barrier = function(scope='A')
{
.Call(R_grid_barrier, private$g_ptr, scope)
invisible(self)
},
#' @details
#' The BLACS integer context.
#' @useDynLib fmlr R_grid_ictxt
ictxt = function() .Call(R_grid_ictxt, private$g_ptr),
#' @details
#' The BLACS integer context.
#' @useDynLib fmlr R_grid_nprocs
nprocs = function() .Call(R_grid_nprocs, private$g_ptr),
#' @details
#' The BLACS integer context.
#' @useDynLib fmlr R_grid_nprow
nprow = function() .Call(R_grid_nprow, private$g_ptr),
#' @details
#' The BLACS integer context.
#' @useDynLib fmlr R_grid_npcol
npcol = function() .Call(R_grid_npcol, private$g_ptr),
#' @details
#' The BLACS integer context.
#' @useDynLib fmlr R_grid_myrow
myrow = function() .Call(R_grid_myrow, private$g_ptr),
#' @details
#' The BLACS integer context.
#' @useDynLib fmlr R_grid_mycol
mycol = function() .Call(R_grid_mycol, private$g_ptr),
#' @details
#' Returns whether or not the grid object is valid.
#' @useDynLib fmlr R_grid_valid_grid
valid_grid = function() .Call(R_grid_valid_grid, private$g_ptr),
#' @details
#' Returns the external pointer data. For developers only.
data_ptr = function() private$g_ptr
),
private = list(
g_ptr = NULL
)
)
#' grid
#'
#' Constructor for MPI grid objects.
#'
#' @details
#' Data is held in an external pointer.
#'
#' @param gridtype Type of processor grid: \code{PROC_GRID_SQUARE},
#' \code{PROC_GRID_WIDE}, or \code{PROC_GRID_TALL}.
#' @return A grid class object.
#'
#' @export
grid = function(gridtype=PROC_GRID_SQUARE)
{
gridR6$new(gridtype=gridtype)
}