58
edits
Changes
→Reference
{{GPU621/DPS921 Index | 20207}}
[mailto:astinziani@myseneca.ca?subject=GPU621 Yuseok Won]
[mailto:astinziani@myseneca.ca?subject=GPU621 Minsu Kim]
[[File:Golang.png|400px|left]] Go Language is a open source programming language that is designed at Google by [https://en.wikipedia.org/wiki/Robert_Griesemer Robert Griesemer], [https://en.wikipedia.org/wiki/Ken_Thompson Ken Thompson], and [https://en.wikipedia.org/wiki/Rob_Pike Rob Pike]. <br>
Go lang is a '''Fast''' and '''Pretty''' language.
[[File:what-is-java-5b4bda1cc9e77c0037171617.jpg|400px|left]]
Java is open source and Objectobject-oriented programming language developed by Sun Microsystems in 1995. The founder is James Gosling. In 2010, Oracle acquired Sun Microsystems and owned Java's copyright.
Java is simple programming language, easy to learn, clean and easy to understand. This is because syntax of Java is based on C++ that has removed many confusing and rarely used functionality by user (e.g. operator overloading, explicit pointer, automatic garbage collection manual memory management etc.)
Java is the platform independent language. Programs can run on several different types of computer as long as computer has a Java Runtime Environment(JRE) installed.
<br>
<br>
'''Parallelism and Concurrency'''
diagram cited by Pithikos in [https://stackoverflow.com/questions/1050222/what-is-the-difference-between-concurrency-and-parallelism Stack Overflow]
'''Implementation''' Go language focuses on concurrency and parallelism by implementing its own Goroutine instead of regular threading. Goroutines uses the built-in scheduler to conduct the threads in behind and hide many complexity of thread management from the user to specify which function to run and execute them with “Go” command.
Java language can implement thread in two three different methods. The first method is to create a class which extends the “Thread” "Thread" class that gives the user to have control of the lifecycle of the thread. But Java language only allows single inheritance which prevents the thread from being extend extending other base class. The second method is using ‘Runnable’ "Runnable" interface. This method allows to user to extend other base class while still being run as a new thread. However, this method does not give user to control lifecycle of thread.The third, Java version 5.0 and later provides "concurrency" to simplify thread creation and processing. The "[https://docs.oracle.com/javase/tutorial/essential/concurrency/executors.html Executor]" that implement by java.util.concurrent provides APIs for creating and processing new threads. =Implementation===General Implementation Info==
''Before diving into the code, here are some things to know.''
'''1. ''' To Increase the accuracy, both Go & Java program will run in terminal using .sh script<br>- To do this, you will need to enable "Root". <br>''Run below command to start root-user terminal'' <br> sudo -s '''2. ''' To Increase the accuracy, both Go & Java program will run in the same environment(/machine <br>- Environment/machine)used for below experiment is:{| class="wikitable" margin-left: left;|-| Machine || Mac Book Pro 2019|-| Processor || 2.3GHz 8-core 16 threads Intel Core i9 |-| macOS || Big Sur 11.5.1|-| Memory || 16GB|-| Go Version || v1.16.6|-| Java Version || v15 2020-09-15 |}'''3.'' ' To run both program, 4096 * 4096 pre-generated Matrix with random values between 0 and 1000 will be used <br>
- Create & Download Matrix here [https://onlinenumbertools.com/random-number-matrix https://onlinenumbertools.com/random-number-matrix]
==Implementation for Go==
===Implementation for Installation of Go===----'''Installation of Go''' <br>
Go to [https://golang.org/dl/ https://golang.org/dl/] & Download Go accordingly to your OS.
package main
runtime.GC()
}
''Above Go code will run in terminal using .sh script.''
#! /bin/sh
echo "Done";
Go to [https://www.java.com/ko/download/manual.jsp https://www.java.com/ko/download/manual.jsp] & Download Java accordingly to your OS. <br>
import java.io.BufferedReader;
import java.io.FileReader;
}
}
''Above Java code will run in terminal using .sh script.''
''' .sh Code to Run Java Program '''
echo "Done";
==Charts==
{| <!-- The nested table must be on a new line -->
| style="border: 2px" |
{| class="wikitable"
|+ Performance difference in Go & Java
| style="padding: 15px;" |
[[File:Parallel Programming in Go & Java.png|400px]]
|}
{| <!-- The nested table must be on a new line -->| style="border: 2px" |{| class="wikitable" margin-left: left;
|+ Performance difference for Java Thread
|-
| 2 threads to 4 threads|| 51.90%
|-
| 4 threads to 8 threads|| 49.49%
|-
| 8 threads to 16 threads|| 8.79%
|}
| style="padding: 15px;" |
{| class="wikitable" margin-left: left;|+ Performance Difference difference for GoThread
|-
! !! difference
| 8 threads to 16 threads|| -20.65%
|}
|style="padding: 15px;"|
{| class="wikitable"
|+ Performance increase of Go in comparsion to Java Thread
|}
|} ==Analysis==Analysis The results of matrix multiplication implementation on Go language has remarkable superiority in main thread. However, the both language shows the tendency that execution time gradually decreases as the number of threads increase. The curve of execution time on the graph become flatten for both Go and Java when the number of threads become 8 and 16. We infer the Go has a reduction tendency when the number of threads reach 8 and 16 but Java shows the promotion tendency as number of threads reach 8 and 16. The best performance has been shown that the 8 threads for Go and 16 threads on Java. The percentage difference of implementation time between GO and Java shows minimum 12% when 16 threads being used and maximum 102% when main thread being used. There is a few possible reason that Go and Java shows difference performance despite using same calculating matrix multiplication algorithm. First, the code for Go and Java is not exactly matched. second, Java uses JVM(Java Virtual Machine) to calculate the algorithm which may take more time to implement. =Reference=https://golang.org/doc/faq#goroutines <br>https://docs.oracle.com/javase/tutorial/essential/concurrency/highlevel.html<br>http://www.oracle.com/technetwork/java/javase/overview/javahistory-index-198355.html<br>https://golang.org/doc/faq#Origins<br>https://www.youtube.com/watch?v=oV9rvDllKEg<br>https://stackoverflow.com/questions/1050222/what-is-the-difference-between-concurrency-and-parallelism<br>https://onlinenumbertools.com/random-number-matrix<br>https://golang.org/dl/<br>https://www.java.com/ko/download/manual.jsp<br>https://docs.oracle.com/javase/tutorial/essential/concurrency/executors.html