#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include <omp.h>

int id = 0;

void create_task(char *name, int parent)
{
#pragma omp task firstprivate(name, parent)
#pragma omp task firstprivate(name, parent)
  {
    sleep(1);
    printf("%s [grandchild of %d] done by %d\n", name, parent, omp_get_thread_num());
  }
}

  
int main()
{
#pragma omp parallel num_threads(2)
  {
    int me ;
    #pragma omp atomic capture
    me = id++;
#pragma omp single nowait
    //#pragma omp taskgroup
    {
      printf("Task %d creates A and B \n", me);
      create_task("A", me);
      create_task("B", me);
    }

#pragma omp taskwait
    printf("Task %d after taskwait \n", me);
    
  }
  return 0;
}
