Difference between revisions of "GPU621/The Chapel Programming Language"

From CDOT Wiki
Jump to: navigation, search
(Language Basics)
(Language Basics)
Line 32: Line 32:
 
  //https://chapel-lang.org/docs/primers/
 
  //https://chapel-lang.org/docs/primers/
 
=== Language Basics ===
 
=== Language Basics ===
 +
 +
==== Variable: ====
 +
 
Variables are declared with the '''var''' keyword.  Variable declarations must have a type, initializer, or both.
 
Variables are declared with the '''var''' keyword.  Variable declarations must have a type, initializer, or both.
  
<code>
+
    var myVariable1: int;
var myVariable1: int;
 
</code>
 
  
 
'''const''' and '''param''' can be used to declare runtime constants and compile-time constants respectively. A '''const''' must be initialized in place, but can have its value generated at runtime. A '''param''' must be known at compile time.
 
'''const''' and '''param''' can be used to declare runtime constants and compile-time constants respectively. A '''const''' must be initialized in place, but can have its value generated at runtime. A '''param''' must be known at compile time.
  
<code> const myConst: real = sqrt(myVariable2);<br>
+
    const myConst: real = sqrt(myVariable2);
param myParam = 3.14; </code>
+
    param myParam = 3.14;
  
 
All three variable kinds can be qualified by the '''config''' keyword.  This allows the initial value to be overridden on the command line.
 
All three variable kinds can be qualified by the '''config''' keyword.  This allows the initial value to be overridden on the command line.
 +
 +
    config var myVariable2: bool = false; //./variable --myVariable=true
 +
 +
==== Procedures: ====
 +
 +
A procedure groups computations that can be called from another part of the program.
 +
 +
    proc factorial(x: int) : int
 +
    {
 +
      if x < 0 then
 +
        halt("factorial -- Sorry, this is not the gamma procedure!");
 +
      return if x == 0 then 1 else x * factorial(x-1);
 +
    }
 +
 +
==== Classes: ====
 +
 +
A class is a type that can contain ''variables'' and ''constants'', ''called fields'', as well as ''functions'' and ''iterators'' called methods.  A new class type is declared using the '''class''' keyword.
 +
 +
    class C {
 +
      var a, b: int;
 +
      proc printFields() {
 +
        writeln("a = ", a, " b = ", b);
 +
      }
 +
    }
 +
 +
The '''new''' keyword creates an instance of a class by calling an initializer.
 +
 +
    var foo = new C(1, 3);
 +
    foo.printFields();
 +
 +
==== Records: ====
 +
 +
Records are similar to classes, but there are several important differences:
  
<code>
+
* classes support inheritance and virtual dispatch while records do not
config var myVariable2: bool = false; //./variable --myVariable=true
+
* different class variables can refer to the same instance, while record variables refer to distinct memory
</code>
+
* copy-initialization and assignment can be implemented for records but not for classes.
  
 
=== Iterators ===
 
=== Iterators ===

Revision as of 13:59, 20 November 2020

Project Description

The Chapel is a portable, scalable, open-source modern parallel programming language designed to be productive. The Chapel is a high-level programming language that tends to be more human-readable and writable with some similarity to Python. The Chapel's performance can compete or even surpass MPI/OpenMP. This project will introduce the main functionality of Chapel programming language, compare the code and performance to C++ MPI/OpenMP, analysis the pros and cons of the Chapel.

Team Members

  1. Xi Weng
  2. Ivan Huang
  3. Yu Li
  4. eMail All

Installation

The Chapel is an open-source language that still constantly updates. The latest version as of the creation of this project is 1.23.0 released on October 15, 2020.

There is currently no official support for The Chapel Programming Language in major known IDE like Visual Studio, which is a downside compared to other languages in terms of usability.

Select one of the following options to install The Chapel Programming Language.


Pre-packaged Chapel installations are available for:

GitHub source code download available here.

Users can also try The Chapel online here, though the version is currently stuck on Chapel 1.20.

The Chapel Programming Language

Main Functionality

//https://chapel-lang.org/docs/primers/

Language Basics

Variable:

Variables are declared with the var keyword. Variable declarations must have a type, initializer, or both.

   var myVariable1: int;

const and param can be used to declare runtime constants and compile-time constants respectively. A const must be initialized in place, but can have its value generated at runtime. A param must be known at compile time.

   const myConst: real = sqrt(myVariable2);
   param myParam = 3.14;

All three variable kinds can be qualified by the config keyword. This allows the initial value to be overridden on the command line.

   config var myVariable2: bool = false; //./variable --myVariable=true

Procedures:

A procedure groups computations that can be called from another part of the program.

   proc factorial(x: int) : int
   {
     if x < 0 then
       halt("factorial -- Sorry, this is not the gamma procedure!");
     return if x == 0 then 1 else x * factorial(x-1);
   }

Classes:

A class is a type that can contain variables and constants, called fields, as well as functions and iterators called methods. A new class type is declared using the class keyword.

   class C {
     var a, b: int;
     proc printFields() {
       writeln("a = ", a, " b = ", b);
     }
   }

The new keyword creates an instance of a class by calling an initializer.

   var foo = new C(1, 3);
   foo.printFields();

Records:

Records are similar to classes, but there are several important differences:

  • classes support inheritance and virtual dispatch while records do not
  • different class variables can refer to the same instance, while record variables refer to distinct memory
  • copy-initialization and assignment can be implemented for records but not for classes.

Iterators

Task Parallelism

Locality

Data Parallelism

Library Utilities

Numerical Libraries

Code Comparesion to MPI & OpenMP

Pros and Cons of Using The Chapel

Adoption

Small Number of Contributors

temp

References