我在想,这个函数指针变量不需要定义也可以。直接传递fortran子程序的地址即可,就是按照你写的代码意思。
在原先的c代码中,实现的方式如下:
c代码:
[C] 纯文本查看 复制代码
void stencil_core(targs* args)
{
int starti=args->starti;
int endi=args->endi;
int startj=args->startj;
int endj=args->endj;
int iter=args->iter;
int i,j,k;
int dest = iter % 2 ;
int src = 1 - dest;
for(i = starti; i < endi; i++)
for(j = startj; j < endj; j++)
for(k = 1; k < args->k_N - 1; k++)
Do3d7pkernel(dest,src,i,j,k);
}
int Do3d7p(const int bkn, const int iter, const int blocsizex, const int blocsizey)
{
__acemesh_task_generator_with_neighbors((TASK_FUNCPTR)stencil_core,
(void*)(&each), sizeof(targs),
NULL, (NEIGHBOR_FUNCPTR)my_neighbors, &each);
}
头文件,b.h:[C] 纯文本查看 复制代码
typedef void (*NEIGHBOR_FUNCPTR)(void** neighbor_addrs, int* num_neigh, void* args);
void __acemesh_task_generator_with_neighbors(void* taskfptr, void* args, unsigned int args_size,
void* cxx_this_pointer, void* get_neighbors_funcptr, void *neighbor_args);
b.cpp:
__acemesh_task_generator_with_neighbors(void* taskfptr, void* args, unsigned int args_size,
void *cxx_this_pointer, void* get_neighbors_funcptr, void *neighbor_args)
{
TASK_FUNCPTR funcptr = (TASK_FUNCPTR)taskfptr;
ci_task* _task = ACEMESH_NEW ci_task(funcptr);
_task->define(args, args_size);
_task->define_neighbors(cxx_this_pointer, get_neighbors_funcptr, neighbor_args);
} |