Changes

Jump to: navigation, search

GPU621/The Chapel Programming Language

2,207 bytes added, 14:22, 2 December 2020
Task Parallelism
==== basic ====
 
Three basic parallel features:
 
'''begin:''' it creates a independent thread. Unable to confirm who will execute first.
 
'''cobeign:''' it creates a block of tasks. The main thread will continue until the statements inside are finished.
 
'''coforall:''' it is a loop of cobegin syntax in which each iteration is a separate task. The main thread will also continue until the loop is finished.
 
The order of execution within each iteration is determined, and the order of iteration will execute first is not determined.
 
An example code:
const numTasks = here.numPUs();
writef("Hello from task %n of %n\n", tid, numTasks);
==== Sync/Singles Single ==== Sync and single are type qualifiers that end with '''$''' when you declare it.  They have an associated state (full/empty); when you declare it with an initializing expression, the statement will be ''full''; otherwise it is ''empty'' and the value of that variable is the default value of its type. '''empty''' is the only state that you can write a value to it, and after writing it changes to '''full'''. '''full''' is the only state that you can read the value from a variable; After reading, '''sync''' variable will change to '''empty''' and '''single''' variable doesn't change.  ===== Methods for sync/single variables: ===== * For both sync and single variables:** '''''isFull''''' - return '''true''' if variable's statement is ''full''.** '''''writeEF()''''' - it will block until variable's statement is ''empty'', then set the argument value.** '''''readFF()''''' - it will block until variable's statement is ''full'', then read the value and return the '''value'''. sync and single variable cannot directly output, use this method to output the value. ** '''''readXX()''''' - return '''true''' regardless variable's statement.* For sync variables only:** '''''reset()''''' - set the value to its type's default value and set statement to '''empty'''.** '''''readFE()''''' - it will block until variable's statement is ''full'', then read the value and return the '''value'''. using this method to output the value.** '''''writeXF()''''' - set the argument value without block the execution.** '''''writeFF()''''' - it will block until variable's statement is ''full'', then set the argument value without change the state. An example code:
var sy$: sync int = 2; // state = full, value = 2
25
edits

Navigation menu