Posts

Showing posts from 2019

Parallel summation of a large array without shared data locks

Image
The traditional producer/consumer pattern employs a shared buffer between the producer and the consumer.   Many producer/consumer problems are simply sequential problems with the overhead of multiple tasks and a shared buffer. Parallel operations, on the other hand, are more naturally concurrent without the locking overhead of a shared buffer. Instead non-overlapping data elements of a collection such as an array are assigned to two or more tasks, and identical tasks process their subsets of the collection without need of locking the collection.   If the parallel task is to sum all the elements in the array then task 1 in the diagram above will sum the elements in the first half of the array while task 2 sums the elements in the second half of the array. Task 1 and task 2 then simply report their subtotals to the parent task which adds the two values and returns the final total. The following source code is an Ada package for parallel addition along with a proced...

Stack Abstract Data Type using Ada

The stack Abstract Data Type is one of the simplest data types to create and understand. There are fundamentally two kinds of stack types. ·          bounded stacks which have a pre-determined capacity ·          unbounded stacks which can grow to the limits of computer memory. Every stack implementation has some common subprograms. ·          Is_Empty – This function returns true if the stack is empty and false if it is not empty ·          Size – A function returning number of elements currently contained by the stack ·          Top – A function returning the top element of a stack that is not empty ·          Push – Push a data element onto the stack ·          Pop – A procedure that pops the ...