mdcore
0.1.5
|
00001 /******************************************************************************* 00002 * This file is part of mdcore. 00003 * Coypright (c) 2010 Pedro Gonnet (pedro.gonnet@durham.ac.uk) 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published 00007 * by the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 ******************************************************************************/ 00019 00020 /* space error codes */ 00021 #define space_err_ok 0 00022 #define space_err_null -1 00023 #define space_err_malloc -2 00024 #define space_err_cell -3 00025 #define space_err_pthread -4 00026 #define space_err_range -5 00027 #define space_err_maxpairs -6 00028 00029 00030 /* some constants */ 00031 #define space_periodic_none 0 00032 #define space_periodic_x 1 00033 #define space_periodic_y 2 00034 #define space_periodic_z 4 00035 #define space_periodic_full 7 00036 #define space_periodic_ghost_x 8 00037 #define space_periodic_ghost_y 16 00038 #define space_periodic_ghost_z 32 00039 #define space_periodic_ghost_full 56 00040 00041 #define space_partlist_incr 100 00042 00044 #define space_maxtuples 4 00045 00047 #define space_verlet_maxpairs 800 00048 00049 00050 /* some useful macros */ 00053 #define space_cellid(s,i,j,k) ( ((i)*(s)->cdim[1] + (j)) * (s)->cdim[2] + (k) ) 00054 00056 #define space_pairind(i,j) ( space_maxtuples*(i) - (i)*((i)+1)/2 + (j) ) 00057 00059 extern int space_err; 00060 00061 00063 struct space { 00064 00066 double dim[3]; 00067 00069 double origin[3]; 00070 00072 int cdim[3]; 00073 00075 double h[3], ih[3]; 00076 00078 double cutoff, cutoff2; 00079 00081 unsigned int period; 00082 00084 int nr_cells; 00085 00087 int *cid_real, *cid_ghost, *cid_marked; 00088 int nr_real, nr_ghost, nr_marked; 00089 00091 struct cell *cells; 00092 00094 int nr_pairs; 00095 00097 struct cellpair *pairs; 00098 00100 int next_pair; 00101 00103 struct celltuple *tuples; 00104 00106 int nr_tuples; 00107 00109 int next_tuple, next_cell; 00110 00112 pthread_mutex_t cellpairs_mutex; 00113 00115 lock_type cellpairs_spinlock; 00116 00118 pthread_cond_t cellpairs_avail; 00119 00121 char *cells_taboo; 00122 00124 char *cells_owner; 00125 00127 struct fifo dispatch_out; 00128 00130 int nr_swaps, nr_stalls; 00131 00133 struct part **partlist; 00134 00136 struct cell **celllist; 00137 00139 int nr_parts, size_parts; 00140 00142 struct verlet_entry *verlet_list; 00143 FPTYPE *verlet_oldx, verlet_maxdx; 00144 int *verlet_nrpairs; 00145 int verlet_size, verlet_next; 00146 int verlet_rebuild; 00147 pthread_mutex_t verlet_force_mutex; 00148 00150 double epot; 00151 00153 #ifdef HAVE_CUDA 00154 float *forces_cuda; 00155 void *cuArray_parts, *parts_cuda; 00156 int *counts_cuda, *counts_cuda_local, *ind_cuda, *ind_cuda_local; 00157 struct cellpair_cuda *pairs_cuda; 00158 struct celltuple_cuda *tuples_cuda; 00159 int *taboo_cuda; 00160 #endif 00161 00162 }; 00163 00164 00166 struct cellpair { 00167 00169 int i, j; 00170 00172 FPTYPE shift[3]; 00173 00175 int size, count; 00176 short int *pairs; 00177 short int *nr_pairs; 00178 00180 struct cellpair *next; 00181 00182 }; 00183 00184 00186 struct celltuple { 00187 00189 int cellid[ space_maxtuples ]; 00190 00192 int n; 00193 00195 int pairid[ space_maxtuples * (space_maxtuples + 1) / 2 ]; 00196 00197 /* Buffer value to keep the size at 64 bytes for space_maxtuples==4. */ 00198 int buff; 00199 00200 }; 00201 00202 00204 struct verlet_entry { 00205 00207 struct part *p; 00208 00210 struct potential *pot; 00211 00213 signed char shift[3]; 00214 00215 }; 00216 00217 00218 /* associated functions */ 00219 int space_init ( struct space *s , const double *origin , const double *dim , double *L , double cutoff , unsigned int period ); 00220 struct cellpair *space_getpair ( struct space *s , int owner , int count , struct cellpair *old , int *err , int wait ); 00221 struct cellpair *space_getpair_spin ( struct space *s , int owner , int count , struct cellpair *old , int *err , int wait ); 00222 int space_releasepair ( struct space *s , int ci , int cj ); 00223 int space_releasepair_spin ( struct space *s , int ci , int cj ); 00224 int space_shuffle ( struct space *s ); 00225 int space_shuffle_local ( struct space *s ); 00226 int space_addpart ( struct space *s , struct part *p , double *x ); 00227 int space_pairs_sort ( struct space *s ); 00228 int space_prepare ( struct space *s ); 00229 int space_maketuples ( struct space *s ); 00230 int space_gettuple ( struct space *s , struct celltuple **out , int wait ); 00231 int space_gettuple_spin ( struct space *s , struct celltuple **out , int wait ); 00232 int space_getpos ( struct space *s , int id , double *x ); 00233 int space_setpos ( struct space *s , int id , double *x ); 00234 int space_flush ( struct space *s ); 00235 int space_verlet_init ( struct space *s , int list_global ); 00236 int space_verlet_get ( struct space *s , int maxcount , int *from ); 00237 int space_verlet_force ( struct space *s , FPTYPE *f , double epot ); 00238 int space_flush_ghosts ( struct space *s ); 00239 int space_getcell ( struct space *s , struct cell **out );