#ifndef SINGUTIL_H
#define SINGUTIL_H

#if !defined(__LANGUAGE_FORTRAN__) && !defined(_LANGUAGE_FORTRAN)

#if defined(__cplusplus)
extern "C"
{
#endif

    typedef enum {
        J_DEVPARA, // JPs are splitted into Ndevice fragments. IPs are shared among all Device[]s.
        I_DEVPARA, // IPs are splitted into Ndevice fragments. JPs are shared among all Device[]s.
    } Devpara;

    int  SING_ndevice(void);
    void SING_set_devpara(Devpara dpara);
    Devpara SING_devpara(void);

    void SING_open(void);
    void SING_close(void);
    void SING_LM_write_regconv(int length, int *conversions);
    void SING_LM_write(void *hostp, int lmoffset, int peeach);
    int  SING_EM_alloc(int length, int *conversions, int size, int *err);
    int  SING_EM_send(int areaid, int start, int ndata, void *hostp);
    void SING_EM_write(int areaid, int start, int ndata, void *hostp);
    void SING_iflush(void);
    void SING_execute(int init_id, int loop_id, int final_id, int loop_count, void *loop_out, void *final_out);
    int  SING_iregister(int ninsts, char **insts);

    int  SING_number_of_pe(void);
    int  SING_number_of_bb(void);
    int  SING_EM_BM_transfer(int areaid, int emstart, int bmstart, int ndata, int mode, int bbid);
    int  SING_BM_alloc(int areaid, int size, int *err);

    void SING_openMC(int devid);
    void SING_closeMC(int devid);
    void SING_LM_write_regconvMC(int devid, int length, int *conversions);
    void SING_LM_writeMC(int devid, void *hostp, int lmoffset, int peeach);
    int  SING_EM_allocMC(int devid, int length, int *conversions, int size, int *err);
    int  SING_EM_sendMC(int devid, int areaid, int start, int ndata, void *hostp);
    void SING_EM_writeMC(int devid, int areaid, int start, int ndata, void *hostp);
    void SING_iflushMC(int devid);
    void SING_executeMC(int devid, int init_id, int loop_id, int final_id, int loop_count, void *loop_out, void *final_out);
    int  SING_iregisterMC(int devid, int ninsts, char **insts);

#if defined(__cplusplus)
}
#endif

#endif /* LANGUAGE_FORTRAN */

#endif /* SINGUTIL_H */
