Research Article: 2021 Vol: 24 Issue: 6S
Franco Ortega, Universidad Vin˜a del Mar
Brandon General, Universidad Vin˜a del Mar
Bairon Vega, Universidad Vin˜a del Mar
Cristian Vidal, Universidad Católica del Norte
Claudia Jiménez, Universidad Vin˜a del Mar
Jose´ Miguel Rubio, Universidad Bernardo O´Higgins
Algorithmic thinking is part of human nature. Nonetheless, writing algorithms in programming languages can be not trivial, mainly for syntax issues. Multi-tasks thinking seems natural for human teams. Nonetheless, implementing multi-tasks solutions can be a complex task for people and students who learn programming languages mainly for syntax issues. Python is a real solution to simplify their programming learning. This article presents and highlights the learning experience of Chilean students to implement multi-task solutions, that is, concurrent and parallel programs, in Python. Those benefits invite us to promote programming using Python in other courses, majors, and institutions. Programming for everybody is nearest now.
Multi-task, Concurrent, Parallel, Programming, Python Solutions
Sequential programming only allows the creation of solutions for sequential execution. The first computer systems were completely sequential; they would run only one program at a time until each of them finished to run another one (Oganjanyan, 2018). That happened even though each running task used only some system resources and others were free during execution. Concurrent computing was born to look for optimizing the use of computing resources. According to Schneider (Schneider, 2012), concurrent computing consists of a set of processes (running programs) and shared resources (CPU, shared memory, or network resources in use). Concurrent programming tries to improve responsiveness by reacting to the occurrence of possibly simultaneous events (network events, user interface, other computers or peripherals) (Sadowski, 2011). Parallel programming allows the parallel use of resources from a particular machine (such as multiple cores) or the set of machines in a cluster to try to improve the performance of computing tasks (Yazdeen, 2021). Thus, the concurrent execution of tasks can be seen as an apparent parallelism (Zhang, 2017).
Figure 1 (Terrell, 2016) illustrates concurrent task execution and parallel task execution. Algorithmic reasoning refers to the identification of tasks for their sequential performance. Thus, the main complexity of a programming solution is the translation of an algorithm into a language. Python is a programming language that reduces these difficulties (Srinath, 2017). Python is a high-level, interpreted programming language with a simple syntax to facilitate its learning and also emphasize the readability of its solutions to reduce its maintenance cost (Manolescu, 2021). For example, there are multiple positive experiences of using Python for teaching in various lines such as first programming language and web systems development (Pandey, 2020; Ellis, 2019). Likewise, there are experiences of teaching and using advanced computing topics in under- graduate courses such as big data (Edifor, 2021; Malik, 2021), machine learning (Lemenkova, 2019; Gupta, 2017) and deep learning (Lafuente, 2021; Raschka, 2017). This work aims to demonstrate the advantages and facilities of the practical teaching of concurrent and parallel computing using the Python programming language. It is considered an experience in the Service Configuration (Conf-Ser) course of the current curriculum of Computer Engineering of the Vin˜a del Mar University (CE-VMU).
Sequential Computing
Before the 1960s, hardware limited computing and programming performance. The optimization of efficiency in a specific machine when executing a specific algorithm (Sewak, 2018) characterized solutions at that time. Sequential programming emerged in the 1960s. Sequential or structured programming is a programming paradigm that allows the division of a program into blocks or programming subroutines for the sequential execution of tasks. Basic structures of sequential computing are the selection (if and switch) and iteration (for and while). The objective of structured programming is to make modular programs with more clarity, quality, easier to maintain, and with fewer errors (Botella Lo´pez, 1979). In recent years, the speed of sequential computers has grown by orders of magnitude due to advances in their design and construction techniques (Moreno, 2014) and the development and standardization of software solutions (for example, the UNIX operating system (Aguilar, 2004). Although sequential computing has made extraordinary advances, it has not been able to demonstrate its successful application in complex problems that require machines that work autonomously, robustly, and efficiently in dynamic and threatening environments (Huerta, 2001). A clear example of this dynamism is working with large volumes of data (BigData) and time limits (Rojas Galeano, 1999).
Concurrent Computing
Concurrent computing refers to the fact that running pro- grams share the available computing resources for the same time, but their execution does not occur at the same time cites tanenbaum 2015 modern. Multiple processes can run on a single processor, giving each process a limited time to run. Thus, only one process runs at a given time. If a process P does not complete its work in a defined time, it stops, and another process starts or resumes its execution. Therefore, process P would run again until it finishes its work. Structuring software systems in a way in concurrent and communicated tasks is an excellent way to handle the complexity of an application cites rajsbaum 2019 mastering. According to Psycharis and Kallia cite psycharis 2017 effects, from the mid-1980s to 2004, increasing the number of instructions per second was the dominant reason for improvements in computer performance. The increasing complexity and time required of computing problems and the physical limitations of hardware demand new efficient forms of computing (Figure 2).
Parallel Computing
The physical limitation makes it impossible to obtain improvements in processing speed. One way of working to achieve potential improvements is with the use of multiple processors (Puyol Moreno, 2014). Parallel computing allows the simultaneous use of multiple processing elements for problem-solving. The processing elements include resources such as a multi-processor computer, a computer network, specialized hardware, or any combination of these (Naiouf, 2011). Thus, dividing a solution into sub-solutions that can be executed simultaneously for the parallel use of computing resources is required.
Python is a high-level, interpreted programming language with a simple syntax, properties that make it very suitable for the teaching-learning process (Koprawi, 2020; Vidal, 2021). Figure 2 shows the classic example of displaying a ‘Hello World’ message in Python where only one command or instruction is needed to write or display the message on the screen (print) and the message to display. The implementation of this example was in the online tool Google Colaboratory (Weiss, 2020). Python also supports modern computing features such as machine learning (Carneiro, 2018), and web application development (Chang, 2019). In addition, Python allows the development of multi-tasking solutions, concurrent and parallel computing solutions.
Advantages of the Multi-Tasking Approach
The multi-task approach is the ability of human beings to perform multiple tasks at the same time (Mele´, 2020). Performing multiple tasks at the same time is not a problem when those tasks are not in conflict. Working simultaneously on jobs can generate considerable advantages in increasing productivity and performance. With multi-task processing, it is possible to finish pending tasks in a single block of time, avoid wasting energy working separately on activities grouped into a single block of time, and save time and space in the schedule. Well-executed multi- tasking would allow large volumes of work thanks to increased performance without compromising quality. In addition to saving time, it translates into economic performance. In computer science, as already described, we work with concurrent, parallel, and distributed computing as a form of multi-task solution. This work presents experiences of the first two.
Concurrent and Parallel Computing with Python
For process and thread creation in Python, we require the Process and Thread constructures of the multiprocessing and threading libraries, respectively. Figures 3 and 5 show exam- ple codes in C language for creating a process and a thread to send parent and child messages, respectively. Figures 4 and 6 present codes with the same purpose in Python. There are already differences in syntax for the syntactic rules of C and Python programming language in these examples. These rules in C usually disturb and distract students from understanding the purpose and usefulness of these functions. Furthermore, since the first programming courses develop sequential computing reasoning, thinking about parallel computing solutions is potentially complex, even though this way of reasoning is very typical for human beings for example, actions of daily life such as walking and talking are usually in parallel and teams of work usually distribute tasks in the team members.
In the Conf-Sev course of CE-VMU, the students were divided into four workgroups to develop solutions, first using concurrency and then parallel computing. As shown in table I and II, each group was assigned a classic interprocess communication problem (Sanchez, 2015). During the course, each group developed and presented their solutions effectively. At the end of the course, each group compared both solutions and presented their advantages and disadvantages.
In all groups, the concurrent solutions were more optimal in execution times, concluding that, in these problems, the multi- threaded solution is more optimal. The students also concluded that this result influenced the fact that these problems require access to shared resources, whose access is of a high cost for parallel solutions, which do not allow reaching the advantages of parallel computing to shine through (Table 1 & Figure 4, 5 and 6).
Table 1 Results of Concurrent Solutions |
|
---|---|
Group | Running time |
Group 1 (Readers and Writerrs) | 18.0049s |
Group 2 (Sleepomg Barber) | 50s |
Group 3 (Dining Philosophers) | 12.0034s |
Group 4 (Producer Consumer) | 2.13s |
This work demonstrates the utility of using Python to teach multi-task programming, concurrent and parallel computing, and allowing students to develop their solutions effectively.
Table 2 Results of Parallel Solutions |
|
---|---|
Group | Execution time |
Group 1 (Readers and Writers) | 18.2471s |
Group 2 (Sleeping Barber) | 78s |
Group 3 (Dinner of Filo´sofos) | 12.2926s |
Group 4 (Producer Consumer) | 2.43s |
This work is just an additional sample of the usefulness of Python for the development of algorithmic skills and, in this case, multi-tasking programming. According to the obtained results, each of the working groups effectively implemented and presented their solutions. As future work, we propose using Python from the first programming courses at the authors’ universities and include examples of multi-task computing without shared resources.