这个系列谈不上多深刻,更谈不上高深。只是想把做论文过程中看到的一些东西记录下来。难免零零碎碎一些。Gromacs作为老牌的分子动力学模拟软件,其优化已经做的相当出色了。我想做的工作主要是将其中的CUDA计算nonbond力的工作移植到OpenCL上来,讲起来容易,可是真正做起来才发现不是这么简单啊。
1.首先对分子动力学不了解,目前也就是皮毛的认识
2.CUDA不了解
3.因为工程是用CMake去管理,这也将会是一个工作量
4.OpenCL在学习中
…………
尽量去做吧,研究生用最后在校的时间按照老师的要求再折腾下吧。
我所阅读的代码的版本是Gromacs4.6.5。欢迎有相同志向和兴趣的一起探讨。
好了,说了这么多,今天要讲的只是一个知识点,用typedef定义一个函数,什么用?下面就知道了:
/* Function that should return a pointer *ptr to memory * of size nbytes. * Error handling should be done within this function. */ typedef void nbnxn_alloc_t (void **ptr, size_t nbytes); /* Function that should free the memory pointed to by *ptr. * NULL should not be passed to this function. */ typedef void nbnxn_free_t (void *ptr);
typedef struct { gmx_cache_protect_t cp0; nbnxn_alloc_t *alloc; nbnxn_free_t *free; gmx_bool bSimple; /* Simple list has na_sc=na_s and uses cj * * Complex list uses cj4 */ int na_ci; /* The number of atoms per i-cluster */ int na_cj; /* The number of atoms per j-cluster */ int na_sc; /* The number of atoms per super cluster */ struct nbnxn_list_work *work; gmx_cache_protect_t cp1; } nbnxn_pairlist_t;
nbnxn_alloc_t *alloc; nbnxn_free_t *free;
这实际上就是用C语言定义类的一个基础模型,就是用结构体实现简单的类功能,有数据有操作。这两个变量实际上就是定义了两个上面类型的函数的指针。
源代码文件名为:nbnxn_pairlist.h