view src/parallel_execution/examples/DebughelloWorld/main.cbc @ 1016:3e8d89f271e2 debugger

debugger branch
author Takato Matsuoka <t.matsuoka@cr.ie.u-ryukyu.ac.jp>
date Wed, 19 Jan 2022 17:51:07 +0900
parents e6778c866876
children a747a99ae1f2
line wrap: on
line source

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


#include "../../../context.h"
#interface "TaskManager.h"
#interface "Hello.h"

int cpu_num = 1;
int length = 102400;
int split = 8;
int* array_ptr;
int gpu_num = 0;
int CPU_ANY = -1;
int CPU_CUDA = -1;

__code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
    // printf("[Debug log] initDataGears in main\n");
    // loopCounter->tree = createRedBlackTree(context);
    loopCounter->i = 0;
    taskManager->taskManager = (union Data*)createDebugTaskManagerImpl(context, cpu_num, gpu_num, 0);
    goto code1();
}

__code code1(struct LoopCounter* loopCounter) {
    // printf("[Debug log] code1 in main\n");
    printf("cpus:\t\t%d\n", cpu_num);
    printf("gpus:\t\t%d\n", gpu_num);
    printf("length:\t\t%d\n", length);
    printf("length/task:\t%d\n", length/split);
    goto createTask1();
}


__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) {
    // printf("[Debug log] createTask1 in main\n");
    Hello* hello = createHelloImpl(context);
    struct DebugTaskManagerImpl *debugTaskManagerImpl = (struct DebugTaskManagerImpl *)context->taskManager->taskManager;
    add_memory_range((void *)hello, sizeof(Hello), &debugTaskManagerImpl->mem);
    par goto hello->h(code2); 
    goto code2();
}


__code code2(struct TaskManager* taskManager) {
    // printf("[Debug log] code2 in main\n");
    goto taskManager->shutdown(exit_code);
}

__code code2_stub(struct Context* context) {
    goto code2(context, &Gearef(context, TaskManager)->taskManager->TaskManager);
}

void init(int argc, char** argv) {
    // printf("[Debug log] init in main\n");
    for (int i = 1; argv[i]; ++i) {
        if (strcmp(argv[i], "-cpu") == 0)
            cpu_num = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-l") == 0)
            length = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-s") == 0)
            split = (int)atoi(argv[i+1]);
        else if (strcmp(argv[i], "-cuda") == 0) {
            gpu_num = 1;
            CPU_CUDA = 0;
        }
    }
}

int main(int argc, char** argv) {
    // printf("[Debug log] main in main\n");
    init(argc, argv);
    goto initDataGears();
}