Posts

Comparison of three algorithms for summing an array of integers

This article shares a comparison of the time taken to sum an array of integers. This article tests three algorithms for summing the array. • A sequential summation using a single Ada task. • A concurrent summation using 16 Ada tasks coordinating using the Ada Rendezvous mechanism. • A concurrent summation using 16 Ada tasks coordinating using a shared buffer. This test personal computer has the following characteristics. • Processor : AMD Ryzen 7 7800X3D 8-Core Processor with baseline speed of  4.20 Ghz • RAM: 64.0 GB (63.2 GB usable) of DDR5 RAM • Operating System: Windows 11 Home The software for this test is written in the Ada programming language using the GNAT Community Edition 2021 compiler. The program source code is contained in three files. There is one custom Ada package defined for this test. The package is named array_sums. Ada packages separate the interface definition from the implementation. The interface definition, or package specification, as it is cal...

Comparing Sleeping Barber Implementations in Java and Ada

Image
  Sleeping Barber Problem  Implemented in Ada and Java.  The Java implementation is taken from  Java Sleeping Barber. Problem Description: Simulate a barber shop with one barber, one barber chair and a waiting room with N chairs for waiting customers. When the barber finishes cutting the hair of one customer he dismisses the customer and goes to the waiting room to see if another customer is waiting. If the customer is waiting the barber cuts the customer's hair. If no customers are waiting the barber goes to sleep on the barber chair. The next customer to arrive must awaken the barber. If all waiting room chairs are full when a new customer arrives that arriving customer will leave the barbershop. If the barbershop is closed all arriving customers will leave the barbershop. The barber will cut the hair of all customers already in a chair when the barbershop closes. In these examples there are 4 chairs in the Barber Shop waiting room. ...

Comparing Array handling in C and Ada

  Problem Description: Find the Median of two merged sorted arrays. This article demonstrates some of the differences in array handling using the C language and the Ada language. C version: int* merge(int arr1[], size_t len1, int arr2[], size_t len2) {     int * const ret = malloc((len1 + len2) * sizeof(int));     int *wr = ret;       // merge the two arrays while they both have values     for(;len1 && len2; ++wr) {         if(*arr1 < *arr2) {                       *wr = *arr1++;             --len1;         } else {             *wr = *arr2++;             --len2;         }     }     // here either len1 or len2 or both are zero     // fill with any residue f...

Parallel Comparison of C++ and Ada Producer-Consumer Implementations

  Producer Consumer Comparison  The C++ source code for this example is taken from the blog post here by Andrew Wei. A detailed description of the C++ software is given in the blog post. This solution is shown in parallel with a corresponding Ada solution. Both C++ and Ada separate interface specifications from implementation. C++ uses the header file, in this case the file named Buffer.hpp, to provide the interface specification for the buffer used in this example. C++ is not very strict about what goes into a header file and what goes into a .cpp file. The Ada version creates an Ada package. The Ada package specification defines the task types named producer_Int and consumer_Int. The buffer shared by all instances of producer_int and consumer_int is defined within the Ada package body file. Interface Specification Files Ada C++ package pc_tasks is task type produce_Int (Id : Natural); task type consume_Int (Id : Natura...