|
| 1 | +with |
| 2 | + Ada.Numerics.Real_Arrays, |
| 3 | + Ada.Text_IO, |
| 4 | + Ada.Integer_Text_IO, |
| 5 | + Ada.Real_Time, |
| 6 | + Ada.Command_line; |
| 7 | + |
| 8 | +procedure transpose is |
| 9 | + |
| 10 | + use |
| 11 | + Ada.Numerics.Real_Arrays, |
| 12 | + Ada.Text_IO, |
| 13 | + Ada.Integer_Text_IO, |
| 14 | + Ada.Real_Time, |
| 15 | + Ada.Command_line; |
| 16 | + |
| 17 | + -- GNAT Integer = int32_t, Long_Integer = int64_t |
| 18 | + Iterations : Natural := 10; |
| 19 | + Order : Natural := 1_000; |
| 20 | + |
| 21 | +begin |
| 22 | + |
| 23 | + Put_Line("Parallel Research Kernels"); |
| 24 | + Put_Line("Ada Serial Transpose B += A^T"); |
| 25 | + |
| 26 | + if Argument_Count > 0 then |
| 27 | + Iterations := Integer'Value(Argument(1)); |
| 28 | + end if; |
| 29 | + if Argument_Count > 1 then |
| 30 | + Order := Integer'Value(Argument(2)); |
| 31 | + end if; |
| 32 | + |
| 33 | + if Iterations < 2 then |
| 34 | + Put_Line("Iteration count must be greater than " & Integer'Image(Iterations) ); |
| 35 | + end if; |
| 36 | + |
| 37 | + Put_Line("Number of iterations =" & Integer'Image(Iterations) ); |
| 38 | + Put_Line("Matrix order =" & Integer'Image(Order) ); |
| 39 | + |
| 40 | + declare |
| 41 | + |
| 42 | + I : Natural := 1; |
| 43 | + J : Natural := 1; |
| 44 | + A : Real_Matrix(1..Order,1..Order); |
| 45 | + B : Real_Matrix(1..Order,1..Order); |
| 46 | + |
| 47 | + T0, T1 : Time; |
| 48 | + DT : Time_Span; |
| 49 | + |
| 50 | + US : constant Time_Span := Microseconds(US => Iterations); |
| 51 | + |
| 52 | + K : Integer := 0; |
| 53 | + Asum : Float := 0.0; |
| 54 | + |
| 55 | + AvgTime : Duration; |
| 56 | + Bytes : Long_Integer; |
| 57 | + Nstream_us : Integer; |
| 58 | + Nstream_time : Long_Float; |
| 59 | + Bandwidth : Long_Float; |
| 60 | + |
| 61 | + begin |
| 62 | + |
| 63 | +-- initialization |
| 64 | + |
| 65 | + for I in 1..Order Loop |
| 66 | + for J in 1..Order Loop |
| 67 | + A(I,J) := Float(0); |
| 68 | + B(I,J) := Float(2); |
| 69 | + end Loop; |
| 70 | + end Loop; |
| 71 | + |
| 72 | +-- run the experiment |
| 73 | + |
| 74 | + for K in 0..Iterations Loop |
| 75 | + |
| 76 | + if K = 1 then |
| 77 | + T0 := Clock; |
| 78 | + end if; |
| 79 | + |
| 80 | + for I in 1..Order Loop |
| 81 | + A(I,J) := A(I,J) + B(I,J); |
| 82 | + end Loop; |
| 83 | + |
| 84 | + end Loop; |
| 85 | + T1 := Clock; |
| 86 | + DT := T1 - T0; |
| 87 | + |
| 88 | +-- validation |
| 89 | + |
| 90 | + for I in 1..Order Loop |
| 91 | + for J in 1..Order Loop |
| 92 | + Asum := Asum + ABS ( A(I,J) ); |
| 93 | + end Loop; |
| 94 | + end Loop; |
| 95 | + |
| 96 | + if Asum /= 0.0 then |
| 97 | + Put_Line("Asum=" & Float'Image(Asum) ); |
| 98 | + else |
| 99 | + Put_Line("Solution validates"); |
| 100 | + Bytes := Long_Integer(Order) * Long_Integer(Order) * Long_Float'Size / 4; |
| 101 | + Nstream_us := DT / US; -- this is per iteration now, thanks to US |
| 102 | + Nstream_time := Long_Float(Nstream_us) / Long_Float(1000000); |
| 103 | + Put_Line("Avg time (s): " & Long_Float'Image(Nstream_time)); |
| 104 | + Bandwidth := Long_Float(Bytes) / Long_Float(Nstream_us); |
| 105 | + Put_Line("Rate (MB/s): " & Long_Float'Image(Bandwidth)); |
| 106 | + -- archived for posterity |
| 107 | + --Put_Line("Bytes=" & Long_Integer'Image(Bytes) ); |
| 108 | + --AvgTime := To_Duration(DT); |
| 109 | + --Put_Line("Total Time: " & Duration'Image(AvgTime) & " seconds"); |
| 110 | + --Put_Line("Integer'Last=" & Integer'Image(Integer'Last) ); |
| 111 | + --Put_Line("Long_Integer'Last=" & Long_Integer'Image(Long_Integer'Last) ); |
| 112 | + end if; |
| 113 | + |
| 114 | + end; |
| 115 | + |
| 116 | +end transpose; |
| 117 | + |
0 commit comments