FStarPUTaskNameParams.hpp 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef FSTARPUTASKNAMEPARAMS_HPP
#define FSTARPUTASKNAMEPARAMS_HPP

#include "../../Utils/FGlobal.hpp"

#include <list>
#include <cstring>
#include <cstdio>

/**
 * This class creates task name for starpu
 * it is used for simgrid (to pass task parameters)
 */
class FStarPUTaskNameParams{
protected:
    std::list<const char*> names;
17 18
    FILE* fout;
    int taskid;
19 20

public:
21 22 23 24
    FStarPUTaskNameParams() : fout(nullptr), taskid(0){
        const char* fname = getenv("SCALFMM_SIMGRIDOUT")?getenv("SCALFMM_SIMGRIDOUT"):"/tmp/scalfmm.out";
        fout = fopen(fname, "w");
        std::cout << "output task name in " << fname << "\n";
25 26 27
    }

    ~FStarPUTaskNameParams(){
28
        fclose(fout);
29 30 31 32 33 34 35 36 37 38 39
        clear();
    }

    void clear(){
        while(names.size()){
            delete[] names.front();
            names.pop_front();
        }
    }

    template <typename ... Params>
40
    const char* print(const char key[], const char format[], Params... args ){
41 42
        const size_t length = 512;
        char* name = new char[length+1];
43
        snprintf(name, length, "%s_%d", key, taskid++);
44 45
        name[length] = '\0';
        names.push_back(name);
46

47
        fprintf(fout, "%s, %d, ", key, taskid);
48 49
        fprintf(fout, format, args...);

50 51 52
        return name;
    }

53 54 55 56 57 58 59 60 61 62 63
    const char* add(const char key[], const char* strToCpy){
        const size_t length = 512;
        char* name = new char[length+1];
        snprintf(name, length, "%s_%d", key, taskid++);
        name[length] = '\0';
        names.push_back(name);

        fprintf(fout, "%s=", name);
        fprintf(fout, strToCpy);

        return name;
64 65 66 67
    }
};

#endif // FSTARPUTASKNAMEPARAMS_HPP