@@ -1056,10 +1056,10 @@ the communications needed in its setup.
1056
1056
"""
1057
1057
function psparse (f,I,J,V,rows,cols;
1058
1058
split_format= true ,
1059
+ subassembled= false ,
1059
1060
assembled= false ,
1060
1061
assemble= true ,
1061
- discover_rows= true ,
1062
- discover_cols= true ,
1062
+ indices = :global ,
1063
1063
restore_ids = true ,
1064
1064
assembly_neighbors_options_rows = (;),
1065
1065
assembly_neighbors_options_cols = (;),
@@ -1073,50 +1073,106 @@ function psparse(f,I,J,V,rows,cols;
1073
1073
# Even the matrix compression step could be
1074
1074
# merged with the assembly step
1075
1075
1076
- map (I,J) do I,J
1077
- @assert I != = J
1078
- end
1076
+ # Checks
1077
+ disassembled = (! subassembled && ! assembled) ? true : false
1079
1078
1080
- if assembled || assemble
1081
- @boundscheck @assert all (i-> ghost_length (i)== 0 ,rows)
1079
+ @assert indices in (:global ,:local )
1080
+ if count ((subassembled,assembled)) == 2
1081
+ error (" Only one of the folling flags can be set to true: subassembled, assembled" )
1082
+ end
1083
+ if indices === :global
1084
+ map (I,J) do I,J
1085
+ @assert I != = J
1086
+ end
1082
1087
end
1083
1088
1084
- if ! assembled && discover_rows
1089
+ if disassembled
1090
+ # TODO If assemble==true, we can (should) optimize the code
1091
+ # to do the conversion from disassembled to (fully) assembled split format
1092
+ # in a single shot.
1093
+ @assert indices === :global
1085
1094
I_owner = find_owner (rows,I)
1086
- rows_sa = map (union_ghost,rows,I,I_owner)
1087
- assembly_neighbors (rows_sa;assembly_neighbors_options_rows... )
1088
- else
1089
- rows_sa = rows
1090
- end
1091
- if discover_cols
1092
1095
J_owner = find_owner (cols,J)
1096
+ rows_sa = map (union_ghost,rows,I,I_owner)
1093
1097
cols_sa = map (union_ghost,cols,J,J_owner)
1098
+ assembly_neighbors (rows_sa;assembly_neighbors_options_rows... )
1094
1099
if ! assemble
1095
- assembly_neighbors (rows_sa;assembly_neighbors_options_cols... )
1100
+ # We only need this if we want a subassembled output.
1101
+ # For assembled output, this call will be deleted when optimizing
1102
+ # the code to do the conversions in a single shot.
1103
+ assembly_neighbors (cols_sa;assembly_neighbors_options_cols... )
1096
1104
end
1097
- else
1105
+ map (map_global_to_local!,I,rows_sa)
1106
+ map (map_global_to_local!,J,cols_sa)
1107
+ values_sa = map (f,I,J,V,map (local_length,rows_sa),map (local_length,cols_sa))
1108
+ if val_parameter (reuse)
1109
+ K = map (precompute_nzindex,values_sa,I,J)
1110
+ end
1111
+ if restore_ids
1112
+ map (map_local_to_global!,I,rows_sa)
1113
+ map (map_local_to_global!,J,cols_sa)
1114
+ end
1115
+ A = PSparseMatrix (values_sa,rows_sa,cols_sa,assembled)
1116
+ if split_format
1117
+ B,cacheB = PartitionedArrays. split_format (A;reuse= true )
1118
+ else
1119
+ B,cacheB = A,nothing
1120
+ end
1121
+ if assemble
1122
+ t = PartitionedArrays. assemble (B,rows;reuse= true ,assembly_neighbors_options_cols)
1123
+ else
1124
+ t = @async B,cacheB
1125
+ end
1126
+ elseif subassembled
1127
+ rows_sa = rows
1098
1128
cols_sa = cols
1099
- end
1100
- map (map_global_to_local!,I,rows_sa)
1101
- map (map_global_to_local!,J,cols_sa)
1102
- values_sa = map (f,I,J,V,map (local_length,rows_sa),map (local_length,cols_sa))
1103
- if val_parameter (reuse)
1104
- K = map (precompute_nzindex,values_sa,I,J)
1105
- end
1106
- if restore_ids
1107
- map (map_local_to_global!,I,rows_sa)
1108
- map (map_local_to_global!,J,cols_sa)
1109
- end
1110
- A = PSparseMatrix (values_sa,rows_sa,cols_sa,assembled)
1111
- if split_format
1112
- B,cacheB = PartitionedArrays. split_format (A;reuse= true )
1113
- else
1114
- B,cacheB = A,nothing
1115
- end
1116
- if assemble
1117
- t = PartitionedArrays. assemble (B,rows;reuse= true ,assembly_neighbors_options_cols)
1118
- else
1129
+ if indices === :global
1130
+ map (map_global_to_local!,I,rows_sa)
1131
+ map (map_global_to_local!,J,cols_sa)
1132
+ end
1133
+ values_sa = map (f,I,J,V,map (local_length,rows_sa),map (local_length,cols_sa))
1134
+ if val_parameter (reuse)
1135
+ K = map (precompute_nzindex,values_sa,I,J)
1136
+ end
1137
+ if indices === :global && restore_ids
1138
+ map (map_local_to_global!,I,rows_sa)
1139
+ map (map_local_to_global!,J,cols_sa)
1140
+ end
1141
+ A = PSparseMatrix (values_sa,rows_sa,cols_sa,assembled)
1142
+ if split_format
1143
+ B,cacheB = PartitionedArrays. split_format (A;reuse= true )
1144
+ else
1145
+ B,cacheB = A,nothing
1146
+ end
1147
+ if assemble
1148
+ t = PartitionedArrays. assemble (B,rows;reuse= true ,assembly_neighbors_options_cols)
1149
+ else
1150
+ t = @async B,cacheB
1151
+ end
1152
+ elseif assembled
1153
+ rows_fa = rows
1154
+ cols_fa = cols
1155
+ if indices === :global
1156
+ map (map_global_to_local!,I,rows_fa)
1157
+ map (map_global_to_local!,J,cols_fa)
1158
+ end
1159
+ values_fa = map (f,I,J,V,map (local_length,rows_fa),map (local_length,cols_fa))
1160
+ if val_parameter (reuse)
1161
+ K = map (precompute_nzindex,values_fa,I,J)
1162
+ end
1163
+ if indices === :global && restore_ids
1164
+ map (map_local_to_global!,I,rows_fa)
1165
+ map (map_local_to_global!,J,cols_fa)
1166
+ end
1167
+ A = PSparseMatrix (values_fa,rows_fa,cols_fa,assembled)
1168
+ if split_format
1169
+ B,cacheB = PartitionedArrays. split_format (A;reuse= true )
1170
+ else
1171
+ B,cacheB = A,nothing
1172
+ end
1119
1173
t = @async B,cacheB
1174
+ else
1175
+ error (" This line should not be reached" )
1120
1176
end
1121
1177
if val_parameter (reuse) == false
1122
1178
return @async begin
@@ -1842,14 +1898,14 @@ end
1842
1898
psystem(I,J,V,I2,V2,rows,cols;kwargs...)
1843
1899
"""
1844
1900
function psystem (I,J,V,I2,V2,rows,cols;
1901
+ subassembled= false ,
1845
1902
assembled= false ,
1846
1903
assemble= true ,
1847
- discover_rows= true ,
1848
- discover_cols= true ,
1904
+ indices = :global ,
1849
1905
restore_ids = true ,
1850
- reuse= Val (false ),
1851
1906
assembly_neighbors_options_rows = (;),
1852
- assembly_neighbors_options_cols = (;)
1907
+ assembly_neighbors_options_cols = (;),
1908
+ reuse= Val (false )
1853
1909
)
1854
1910
1855
1911
# TODO this is just a reference implementation
@@ -1858,19 +1914,18 @@ function psystem(I,J,V,I2,V2,rows,cols;
1858
1914
# that we want to generate a matrix and a vector
1859
1915
1860
1916
t1 = psparse (I,J,V,rows,cols;
1917
+ subassembled,
1861
1918
assembled,
1862
1919
assemble,
1863
- discover_rows,
1864
- discover_cols,
1865
1920
restore_ids,
1866
1921
assembly_neighbors_options_rows,
1867
1922
assembly_neighbors_options_cols,
1868
1923
reuse= true )
1869
1924
1870
1925
t2 = pvector (I2,V2,rows;
1926
+ subassembled,
1871
1927
assembled,
1872
1928
assemble,
1873
- discover_rows,
1874
1929
restore_ids,
1875
1930
assembly_neighbors_options_rows,
1876
1931
reuse= true )
0 commit comments