Open main menu

CDOT Wiki β

Changes

GPU621/The Chapel Programming Language

1,338 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 ===
 
The built-in type locale is used to represent locales in Chapel. When a task is trying to access a variable within the same locale, the cost is less compared to accessing a variable from another locale.
'''numLocales:''' a built-in variable which returns the number of locales for the current program as an integer.
use Time;
config const quiet: bool = false;
/* Create a Timer t */
t.stop();
If !quiet then { /* return time in milliseconds that was recorded by the timer */ writeln(t.elapsed(TimeUnits.milliseconds)); }
t.clear();
'''List:''' the list type can be imported using the following statement:
private use List; config const quiet: bool = false;
var new_list: list(int) = 1..5;
'''insert(index, value):''' used to insert the value at the specified index.
=== Numerical Libraries =Comparison to OpenMP == // Chapel is short and concise.
== Comparesion to MPI & OpenMP ==
// OpenMP code
for(iter i = 0 ; iteri<niter; iteri++) { if(iter == 1) start_time();
#pragma omp parallel for
for(…) {} //application loop
}
stop_time();
// Chapel code
for iter i in 01..#niter { if iter == 1 then start_time(); forall .. {} //application loop
}
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);
}
 
//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));
== Pros and Cons of Using The Chapel ==
* 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