Values in Cilk

Cilk has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

#include <cilk/cilk.h>
#include <stdio.h>
#include <stdbool.h>

int main() {
    // Strings, which can be concatenated with strcat() function
    char result[20] = "cilk";
    strcat(result, "lang");
    printf("%s\n", result);

    // Integers and floats
    printf("1+1 = %d\n", 1 + 1);
    printf("7.0/3.0 = %f\n", 7.0 / 3.0);

    // Booleans, with boolean operators as you'd expect
    printf("%s\n", (true && false) ? "true" : "false");
    printf("%s\n", (true || false) ? "true" : "false");
    printf("%s\n", (!true) ? "true" : "false");

    return 0;
}

To run the program, compile it with a Cilk-compatible compiler and then execute the resulting binary:

$ cilk++ values.cilk -o values
$ ./values
cilklang
1+1 = 2
7.0/3.0 = 2.333333
false
true
false

In this Cilk example, we demonstrate various value types and operations:

  1. Strings: Cilk uses C-style strings. We use the strcat() function to concatenate strings.

  2. Integers and floats: These work similarly to other C-based languages.

  3. Booleans: Cilk uses the C99 <stdbool.h> header for boolean types. We use the ternary operator to print “true” or “false” based on the boolean expressions.

  4. Printing: We use the standard C printf() function for output.

Note that Cilk is an extension of C, so it retains most of C’s syntax and features while adding parallel computing capabilities. In this basic example, we haven’t utilized any of Cilk’s parallel features, but they would be useful for more complex, parallelizable computations.