Open main menu

CDOT Wiki β

Changes

GPU621/The Chapel Programming Language

5,757 bytes added, 18:22, 4 December 2020
Library Utilities
# [mailto:xweng11@myseneca.ca?subject=GPU621 Xi Weng]
# [mailto:hbhuang2@myseneca.ca?subject=GPU621 Ivan Huang]
# [mailto:yli593@myseneca.ca?subject=GPU621 Yu (Jackie) Li]
# [mailto:xweng11@myseneca.ca;hbhuang2@myseneca.ca;yli593@myseneca.ca?subject=GPU621 eMail All]
=== Locality ===
numLocales: a The built-in type locale is used to represent locales in Chapel. When a task is trying to access a variable which returns within the number of locales for same locale, the current program as an integercost is less compared to accessing a variable from another locale.
Locales array'''numLocales: ''' a built-in array, variable which stores returns the locale values number of locales for the current program as elements in the array. The ID of each locale value is its index in the Locales arrayan integer.
'''Locales array:''' a built-in array, which stores the locale values for the program as elements in the array. The ID of each locale value is its index in the Locales array. '''Here: ''' a built-in variable which returns the locale value that the current task is running on. In Chapel, all programs begin execution from locale #0.
=== Data Parallelism ===
 
'''Forall-loop:''' important concept in Chapel for data parallelism. Like the coforall-loops, the forall-loop is also a parallel version of a for-loop in Chapel. The motivation behind forall-loops is to be able to handle a large number of iterations without having to create a task for every iteration like the coforall-loop.
 
const n = 1000000;
var iterations: [1..n] real;
 
Each task will be responsible for a single iteration. Significant performance hit caused by creating, scheduling, and destroying each individual task which will outweigh the benefits of each task handling little computation.
 
coforall it in iterations do {
it += 1.0;
}
 
Automatically creates an appropriate number of tasks specific to each system and assigns an equal amount of loop iterations to each task. The number of tasks created is generally based on the number of cores that the system’s processor has. For example: a quad-core processor running this program with 1,000,000 iterations would cause 4 tasks to be created and assign 250,000 iterations to each individual task.
 
forall it in iterations do {
it += 1.0;
}
 
[[File:Chapel_loops.png]]
 
=== Library Utilities ===
=== Numerical Libraries ===
== Code Comparesion to MPI & OpenMP =='''Time Module''' '''Timer:''' a timer is part of the time module which can be imported using the following statement:  use Time; /* Create a Timer t */ var t: Timer; t.start(); writeln(“Operation start”); sleep(5); writeln(“Operation end”); t.stop(); /* return time in milliseconds that was recorded by the timer */ writeln(t.elapsed(TimeUnits.milliseconds)); t.clear();  '''List Module'''
'''List:''' the list type can be imported using the following statement:  use List; var new_list: list(int) =1..5; writeln(new_list); '''Output: [1, 2, 3, 4, 5]'''  for i in 6..10 do { new_list.append(i); } writeln(new_list); '''Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]'''  /* parSafe needs to be set to true if the list is going to be used in parallel */ var new_list2: list(int, parSafe= Pros true); forall i in 0..5 with (ref new_list2) { new_list2.append(i); } writeln(new_list2); '''Output: [0, 1, 2, 3, 4, 5]''' '''sort():''' used to sort the list in ascending order. '''pop(index):''' used to pop the element at the specified index. '''clear():''' used to clear all elements from the list. '''indexOf(value):''' used to retrieve the index of the value specified, returns -1 if not found. '''insert(index, value):''' used to insert the value at the specified index. == Comparison to OpenMP == // Chapel is short and Cons of Using The concise.  // OpenMP code for(i = 0 ; i<niter; i++) { start_time(); #pragma omp parallel for for(…) {} } stop_time();   // Chapel code for i in 1..niter { start_time(); forall .. {} } stop_time(); }  //Hello World OpenMP #include <iostream> #include <omp.h> #include <chrono> using namespace std::chrono; // report system time void reportTime(const char* msg, steady_clock::duration span) { auto ms = duration_cast<milliseconds>(span); std::cout << msg << " - took - " << ms.count() << " milliseconds" << std::endl; } int main() { steady_clock::time_point ts, te; ts = steady_clock::now(); #pragma omp parallel { int tid =omp_get_thread_num(); int nt = omp_get_num_threads(); printf("Hello from task %d of %d \n", tid, not); } te =steady_clock::now(); reportTime("Integration", te - ts); }
Adoption //Hello World Chapel use Time; var t: Timer; //const numTasks = here.numPUs(); const numTasks = 8; t.start(); coforall tid in 1..numTasks do writef("Hello from task %n of %n \n", tid, numTasks); t.stop(); writeln(t.elapsed(TimeUnits.milliseconds));
Small Number == Pros and Cons of ContributorsUsing The Chapel =====Pros===* GitHub open-source.* similarly readable/writable as Python.* the compiler is getting faster and producing faster code. Comparable to OpenMP/MPI.* there are lots of examples, tutorials and documentation available.* a global namespace supporting direct access to local or remote variables.* data parallelism & task parallelism.* friendly community.
== temp =Cons===* lack of a native Windows version.* Adoption, hard to gain user compare to another parallel programming platform.* User base is very small. * It certainly will not be used in the IT industry for the near future(or ever) unless you are opening your own company and decided to try Chapel.* a small number of contributors to this open-source project. Much less support and update compare to other IT giants.* Projects based on Chapel is very little.* It's more for research projects than products. * the package is easy to install, but not as easy as other tools like OpenMP/MPI.* there’s no central place where other people could look for your work if you wanted to have it as an external package.* users have no much reason to start trying the language, given better options like C++ & OpenMP/MPI.
= References =
* The Chapel Overview Talk Video: https://youtu.be/ko11tLuchvg
* The Chapel Overview Talk Slide: https://chapel-lang.org/presentations/ChapelForHPCKM-presented.pdf
* Comparative Performance and Optimization of Chapel: https://chapel-lang.org/CHIUW/2017/kayraklioglu-slides.pdf
* The Parallel Research Kernels: https://www.nas.nasa.gov/assets/pdf/ams/2016/AMS_20161013_VanDerWijngaart.pdf
19
edits