open Printf open Mpi (* comm_size, comm_rank *) let size = comm_size comm_world let myrank = comm_rank comm_world let print_array array = printf "myrank is %d:\n" myrank; for i=1 to (Array.length array) do print_int array.(i-1);print_string ";" done; print_newline () let print_farray array = printf "myrank is %d:\n" myrank; for i=1 to (Array.length array) do print_float array.(i-1);print_string ";" done; print_newline () let _ = printf "%d: comm_size = %d" myrank size; print_newline() (* land,lor,xor is bitwise logical operations *) let _ = if myrank=0 then printf "sum result:%d\n" (reduce_int myrank Int_sum 0 comm_world) else ignore(reduce_int myrank Int_sum 0 comm_world) let _ = if myrank=0 then printf "prod result:%d\n" (reduce_int myrank Int_prod 0 comm_world) else ignore(reduce_int myrank Int_prod 0 comm_world) let _ = if myrank=0 then printf "max result:%d\n" (reduce_int myrank Int_max 0 comm_world) else ignore(reduce_int myrank Int_max 0 comm_world) let _ = if myrank=0 then printf "min result:%d\n" (reduce_int myrank Int_min 0 comm_world) else ignore(reduce_int myrank Int_min 0 comm_world) let _ = if myrank=0 then printf "land result:%d\n" (reduce_int myrank Int_land 0 comm_world) else ignore(reduce_int myrank Int_land 0 comm_world) let _ = if myrank=0 then printf "lor result:%d\n" (reduce_int myrank Int_lor 0 comm_world) else ignore(reduce_int myrank Int_lor 0 comm_world) let _ = if myrank=0 then printf "xor result:%d\n" (reduce_int myrank Int_xor 0 comm_world) else ignore(reduce_int myrank Int_xor 0 comm_world) let _ = if myrank=0 then printf "\nfloating point operations:\n\n" let _ = barrier comm_world let _ = if myrank=0 then printf "sum result:%f\n" (reduce_float (float_of_int myrank) Float_sum 0 comm_world) else ignore(reduce_float (float_of_int myrank) Float_sum 0 comm_world) let _ = if myrank=0 then printf "prod result:%f\n" (reduce_float (float_of_int myrank) Float_prod 0 comm_world) else ignore(reduce_float (float_of_int myrank) Float_sum 0 comm_world) let _ = if myrank=0 then printf "max result:%f\n" (reduce_float (float_of_int myrank) Float_max 0 comm_world) else ignore(reduce_float (float_of_int myrank) Float_max 0 comm_world) let _ = if myrank=0 then printf "min result:%f\n" (reduce_float (float_of_int myrank) Float_min 0 comm_world) else ignore(reduce_float (float_of_int myrank) Float_min 0 comm_world) let _ = let a = Array.make 2 0 in reduce_int_array [|1;2|] a Int_sum 0 comm_world; if myrank=0 then print_array a let _ = let a = Array.make 2 0 in reduce_int_array [|1;2|] a Int_prod 0 comm_world; if myrank=0 then print_array a let _ = let a = Array.make 2 0 in reduce_int_array [|1;2|] a Int_max 0 comm_world; if myrank=0 then print_array a let _ = let a = Array.make 2 0 in reduce_int_array [|1;2|] a Int_min 0 comm_world; if myrank=0 then print_array a let _ = let a = Array.make 2 0.0 in reduce_float_array [|1.0;2.0|] a Float_sum 0 comm_world; if myrank=0 then print_farray a let _ = let a = Array.make 2 0.0 in reduce_float_array [|1.0;2.0|] a Float_prod 0 comm_world; if myrank=0 then print_farray a let _ = let a = Array.make 2 0.0 in reduce_float_array [|1.0;2.0|] a Float_max 0 comm_world; if myrank=0 then print_farray a let _ = let a = Array.make 2 0.0 in reduce_float_array [|1.0;2.0|] a Float_min 0 comm_world; if myrank=0 then print_farray a