QUARK  0.9.0
QUARK-QUeuingAndRuntimeforKernels
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
hello_world.c
Go to the documentation of this file.
1 #include <string.h>
2 #include <stdlib.h>
3 
4 #include "quark.h"
5 
6 /* A task printing a character from a string */
7 /* Printed character is x'ed out, changing the string */
8 void hello_world_task( Quark *quark ) {
9  int idx; char *str;
10  quark_unpack_args_2( quark, idx, str );
11  printf( "%c - from the thread rank %d\n", str[idx], QUARK_Thread_Rank(quark) );
12  str[idx] = 'x';
13 }
14 
15 
16 void test1( Quark *quark ) {
17  int idx;
18  char str[] = "Hello World";
19  printf( "Initial contents of string: %s\n", str );
20  printf( "Each QUARK task will print off a character from string, and replace it with an x.\n" );
21  printf( "The dependencies are all INPUT, so all the tasks can run in parallel.\n" );
22  for ( idx=0; idx<strlen(str); idx++ ) {
23  QUARK_Insert_Task( quark, hello_world_task, NULL,
24  sizeof(int), &idx, VALUE,
25  strlen(str)*sizeof(char), str, INPUT,
26  0 );
27  }
28  QUARK_Barrier( quark );
29  printf( "Final contents of string: %s\n\n", str );
30 }
31 
32 void test2( Quark *quark ) {
33  int idx;
34  char str[] = "Hello World";
35  printf( "Initial contents of string: %s\n", str );
36  printf( "Each QUARK task will print off a character from string, and replace it with an x.\n" );
37  printf( "The dependencies are all INOUT, so all the tasks are serialized.\n" );
38  printf( "Because of locality and serialization, the tasks will all run on one thread.\n" );
39  for ( idx=0; idx<strlen(str); idx++ ) {
40  QUARK_Insert_Task( quark, hello_world_task, NULL,
41  sizeof(int), &idx, VALUE,
42  strlen(str)*sizeof(char), str, INOUT,
43  0 );
44  }
45  QUARK_Barrier( quark );
46  printf( "Final contents of string: %s\n\n", str );
47 }
48 
49 main() {
50  Quark *quark = QUARK_New( 3 );
51  printf( "QUARK is going to use 3 threads.\n\n" );
52  test1( quark );
53  test2( quark );
54  QUARK_Delete( quark );
55 }