@@ -84,7 +84,9 @@ const LOR = Op(MPI_LOR)
84
84
const LXOR = Op (MPI_LXOR)
85
85
const MAX = Op (MPI_MAX)
86
86
const MIN = Op (MPI_MIN)
87
+ const NO_OP = Op (MPI_NO_OP)
87
88
const PROD = Op (MPI_PROD)
89
+ const REPLACE = Op (MPI_REPLACE)
88
90
const SUM = Op (MPI_SUM)
89
91
90
92
mutable struct Request
@@ -95,7 +97,6 @@ const REQUEST_NULL = Request(MPI_REQUEST_NULL, nothing)
95
97
96
98
mutable struct Info
97
99
val:: Cint
98
- # val::Cint
99
100
function Info ()
100
101
newinfo = Ref {Cint} ()
101
102
ccall (MPI_INFO_CREATE, Void, (Ptr{Cint}, Ptr{Cint}), newinfo, & 0 )
@@ -105,8 +106,15 @@ mutable struct Info
105
106
info. val = MPI_INFO_NULL ) )
106
107
info
107
108
end
109
+
110
+ function Info (val:: Cint )
111
+ if val != MPI_INFO_NULL
112
+ error (" Info can only be created using Info()" )
113
+ end
114
+ return new (MPI_INFO_NULL)
115
+ end
108
116
end
109
- const INFO_NULL = MPI_INFO_NULL
117
+ const INFO_NULL = Info ( MPI_INFO_NULL)
110
118
111
119
# the info functions assume that Fortran hidden arguments are placed at the end of the argument list
112
120
function Info_set (info:: Info ,key:: AbstractString ,value:: AbstractString )
@@ -149,6 +157,17 @@ Get_error(stat::Status) = Int(stat.val[MPI_ERROR])
149
157
Get_source (stat:: Status ) = Int (stat. val[MPI_SOURCE])
150
158
Get_tag (stat:: Status ) = Int (stat. val[MPI_TAG])
151
159
160
+ mutable struct Win
161
+ val:: Cint
162
+ Win () = new (0 )
163
+ end
164
+
165
+ struct LockType
166
+ val:: Cint
167
+ end
168
+ const LOCK_EXCLUSIVE = LockType (MPI_LOCK_EXCLUSIVE)
169
+ const LOCK_SHARED = LockType (MPI_LOCK_SHARED)
170
+
152
171
const ANY_SOURCE = Int (MPI_ANY_SOURCE)
153
172
const ANY_TAG = Int (MPI_ANY_TAG)
154
173
const TAG_UB = Int (MPI_TAG_UB)
@@ -814,18 +833,154 @@ function Exscan(object::T, op::Op, comm::Comm) where T
814
833
Exscan (sendbuf,1 ,op,comm)
815
834
end
816
835
836
+ function Win_create (base:: Array{T} , info:: Info , comm:: Comm , win:: Win ) where T
837
+ out_win = Ref (win. val)
838
+ ccall (MPI_WIN_CREATE, Void,
839
+ (Ptr{T}, Ref{Cptrdiff_t}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}),
840
+ base, Cptrdiff_t (length (base)), sizeof (T), info. val, comm. val, out_win, 0 )
841
+ win. val = out_win[]
842
+ end
843
+
844
+ function Win_create_dynamic (info:: Info , comm:: Comm , win:: Win )
845
+ out_win = Ref (win. val)
846
+ ccall (MPI_WIN_CREATE_DYNAMIC, Void,
847
+ (Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}),
848
+ info. val, comm. val, out_win, 0 )
849
+ win. val = out_win[]
850
+ end
851
+
852
+ function Win_attach (win:: Win , base:: Array{T} ) where T
853
+ ccall (MPI_WIN_ATTACH, Void,
854
+ (Ref{Cint}, Ptr{T}, Ref{Cptrdiff_t}, Ref{Cint}),
855
+ win. val, base, Cptrdiff_t (sizeof (base)), 0 )
856
+ end
857
+
858
+ function Win_detach (win:: Win , base:: Array{T} ) where T
859
+ ccall (MPI_WIN_DETACH, Void,
860
+ (Ref{Cint}, Ptr{T}, Ref{Cint}),
861
+ win. val, base, 0 )
862
+ end
863
+
864
+ function Win_fence (assert:: Integer , win:: Win )
865
+ ccall (MPI_WIN_FENCE, Void, (Ref{Cint}, Ref{Cint}, Ref{Cint}), assert, win. val, 0 )
866
+ end
867
+
868
+ function Win_flush (rank:: Integer , win:: Win )
869
+ ccall (MPI_WIN_FLUSH, Void, (Ref{Cint}, Ref{Cint}, Ref{Cint}), rank, win. val, 0 )
870
+ end
871
+
872
+ function Win_free (win:: Win )
873
+ ccall (MPI_WIN_FREE, Void, (Ref{Cint}, Ref{Cint}), win. val, 0 )
874
+ end
875
+
876
+ function Win_sync (win:: Win )
877
+ ccall (MPI_WIN_SYNC, Void, (Ref{Cint}, Ref{Cint}), win. val, 0 )
878
+ end
879
+
880
+ function Win_sync (win:: CWin )
881
+ ccall (:MPI_Win_sync , Void, (CWin,), win)
882
+ end
883
+
884
+ function Win_lock (lock_type:: LockType , rank:: Integer , assert:: Integer , win:: Win )
885
+ ccall (MPI_WIN_LOCK, Void,
886
+ (Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}),
887
+ lock_type. val, rank, assert, win. val, 0 )
888
+ end
889
+
890
+ function Win_unlock (rank:: Integer , win:: Win )
891
+ ccall (MPI_WIN_UNLOCK, Void, (Ref{Cint}, Ref{Cint}, Ref{Cint}), rank, win. val, 0 )
892
+ end
893
+
894
+ function Get (origin_buffer:: MPIBuffertype{T} , count:: Integer , target_rank:: Integer , target_disp:: Integer , win:: Win ) where T
895
+ ccall (MPI_GET, Void,
896
+ (Ptr{T}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cptrdiff_t}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}),
897
+ origin_buffer, count, mpitype (T), target_rank, Cptrdiff_t (target_disp), count, mpitype (T), win. val, 0 )
898
+ end
899
+ function Get (origin_buffer:: Array{T} , target_rank:: Integer , win:: Win ) where T
900
+ count = length (origin_buffer)
901
+ Get (origin_buffer, count, target_rank, 0 , win)
902
+ end
903
+ function Get (origin_value:: Ref{T} , target_rank:: Integer , win:: Win ) where T
904
+ Get (origin_value, 1 , target_rank, 0 , win)
905
+ end
906
+
907
+ function Put (origin_buffer:: MPIBuffertype{T} , count:: Integer , target_rank:: Integer , target_disp:: Integer , win:: Win ) where T
908
+ ccall (MPI_PUT, Void,
909
+ (Ptr{T}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cptrdiff_t}, Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}),
910
+ origin_buffer, count, mpitype (T), target_rank, Cptrdiff_t (target_disp), count, mpitype (T), win. val, 0 )
911
+ end
912
+ function Put (origin_buffer:: Array{T} , target_rank:: Integer , win:: Win ) where T
913
+ count = length (origin_buffer)
914
+ Put (origin_buffer, count, target_rank, 0 , win)
915
+ end
916
+ function Put (origin_value:: Ref{T} , target_rank:: Integer , win:: Win ) where T
917
+ Put (origin_value, 1 , target_rank, 0 , win)
918
+ end
919
+
920
+ function Fetch_and_op (sourceval:: MPIBuffertype{T} , returnval:: MPIBuffertype{T} , target_rank:: Integer , target_disp:: Integer , op:: Op , win:: Win ) where T
921
+ ccall (MPI_FETCH_AND_OP, Void,
922
+ (Ptr{T}, Ptr{T}, Ref{Cint}, Ref{Cint}, Ref{Cptrdiff_t}, Ref{Cint}, Ref{Cint}, Ref{Cint}),
923
+ sourceval, returnval, mpitype (T), target_rank, Cptrdiff_t (target_disp), op. val, win. val, 0 )
924
+ end
925
+
926
+ function Fetch_and_op (sourceval:: MPIBuffertype{T} , returnval:: MPIBuffertype{T} , target_rank:: Integer , target_disp:: Integer , op:: Op , win:: CWin ) where T
927
+ ccall (:MPI_Fetch_and_op , Void,
928
+ (Ptr{T}, Ptr{T}, Cint, Cint, Cptrdiff_t, Cint, CWin),
929
+ sourceval, returnval, mpitype (T), target_rank, target_disp, op. val, win)
930
+ end
931
+
932
+ function Get_address (location:: MPIBuffertype{T} ) where T
933
+ addr = Ref {Cptrdiff_t} (0 )
934
+ ccall (MPI_GET_ADDRESS, Void, (Ptr{T}, Ref{Cptrdiff_t}, Ref{Cint}), location, addr, 0 )
935
+ # ccall(:MPI_Get_address, Int, (Ptr{Void}, Ref{Cptrdiff_t}), location, addr)
936
+ return addr[]
937
+ end
938
+
939
+ function Comm_get_parent ()
940
+ comm_id = Ref {Cint} ()
941
+ ccall (MPI_COMM_GET_PARENT, Void, (Ref{Cint}, Ref{Cint}), comm_id, 0 )
942
+ return Comm (comm_id[])
943
+ end
944
+
945
+ function Comm_spawn (command:: String , argv:: Vector{String} , nprocs:: Integer , comm:: Comm , errors = Vector {Cint} (nprocs))
946
+ c_intercomm = Ref {CComm} ()
947
+ ccall (:MPI_Comm_spawn , Void,
948
+ (Cstring, Ptr{Ptr{Cchar}}, Cint, CInfo, Cint, CComm, Ref{CComm}, Ptr{Cint}),
949
+ command, argv, nprocs, CInfo (INFO_NULL), 0 , CComm (comm), c_intercomm, errors)
950
+ return Comm (c_intercomm[])
951
+ end
952
+
953
+ function Intercomm_merge (intercomm:: Comm , flag:: Bool )
954
+ comm_id = Ref {Cint} ()
955
+ ccall (MPI_INTERCOMM_MERGE, Void, (Ref{Cint}, Ref{Cint}, Ref{Cint}, Ref{Cint}), intercomm. val, Cint (flag), comm_id, 0 )
956
+ return Comm (comm_id[])
957
+ end
958
+
817
959
# Conversion between C and Fortran Comm handles:
818
960
if HAVE_MPI_COMM_C2F
819
961
# use MPI_Comm_f2c and MPI_Comm_c2f
820
962
Base. convert (:: Type{CComm} , comm:: Comm ) =
821
963
ccall (:MPI_Comm_f2c , CComm, (Cint,), comm. val)
822
964
Base. convert (:: Type{Comm} , ccomm:: CComm ) =
823
965
Comm (ccall (:MPI_Comm_c2f , Cint, (CComm,), ccomm))
966
+ # Assume info is treated the same way
967
+ Base. convert (:: Type{CInfo} , info:: Info ) =
968
+ ccall (:MPI_Info_f2c , CInfo, (Cint,), info. val)
969
+ Base. convert (:: Type{Info} , cinfo:: CInfo ) =
970
+ Info (ccall (:MPI_Info_c2f , Cint, (CInfo,), cinfo))
971
+ Base. convert (:: Type{CWin} , win:: Win ) =
972
+ ccall (:MPI_Win_f2c , CWin, (Cint,), win. val)
973
+ Base. convert (:: Type{Win} , cwin:: CWin ) =
974
+ Win (ccall (:MPI_Win_c2f , Cint, (CWin,), cwin))
824
975
elseif sizeof (CComm) == sizeof (Cint)
825
976
# in MPICH, both C and Fortran use identical Cint comm handles
826
977
# and MPI_Comm_c2f is not provided.
827
978
Base. convert (:: Type{CComm} , comm:: Comm ) = reinterpret (CComm, comm. val)
828
979
Base. convert (:: Type{Comm} , ccomm:: CComm ) = Comm (reinterpret (Cint, ccomm))
980
+ Base. convert (:: Type{CInfo} , info:: Info ) = reinterpret (CInfo, info. val)
981
+ Base. convert (:: Type{Info} , cinfo:: CInfo ) = Info (reinterpret (Cint, cinfo))
982
+ Base. convert (:: Type{CWin} , win:: Win ) = reinterpret (CWin, win. val)
983
+ Base. convert (:: Type{Win} , cwin:: CWin ) = Win (reinterpret (Cint, cwin))
829
984
else
830
985
warn (" No MPI_Comm_c2f found - conversion to/from MPI.CComm will not work" )
831
986
end
0 commit comments