typedef struct s_pft_data {
t_moldyn *moldyn;
- int i;
+ int start,end;
} t_pft_data;
void *potential_force_thread(void *ptr) {
// optimized
params=moldyn->pot_params;
+ /* get energy, force and virial for atoms */
- /* get energy, force and virial of every atom */
-
- /* first (and only) loop over atoms i */
- for(i=0;i<count;i++) {
+ for(i=pft_data->start;i<pft_data->end;i++) {
if(!(itom[i].attr&ATOM_ATTR_3BP))
- continue;
+ return 0;
link_cell_neighbour_index(moldyn,
(itom[i].r.x+moldyn->dim.x/2)/lc->x,
#endif
}
+
+ } // i loop
#ifdef DEBUG
//printf("\n\n");
printf("\n\n");
#endif
- }
-
#ifdef DEBUG
//printf("\nATOM 0: %f %f %f\n\n",itom->f.x,itom->f.y,itom->f.z);
if(moldyn->time>DSTART&&moldyn->time<DEND) {
}
- i=0;
- while(i<count) {
-
- /* start threads */
- for(j=0;j<MAX_THREADS;j++) {
-
- /* break if all atoms are processed */
- if(j+i==count)
- break;
-
- /* prepare thread data */
- pft_data[j].moldyn=moldyn;
- pft_data[j].i=j+i;
+ /* start threads */
+ for(j=0;j<MAX_THREADS;j++) {
- ret=pthread_create(&(pft_thread[j]),NULL,
- potential_force_thread,
- &(pft_data[j]));
- if(ret) {
- perror("[albe fast] pf thread create");
- return ret;
- }
+ /* prepare thread data */
+ pft_data[j].moldyn=moldyn;
+ pft_data[j].start=j*count/MAX_THREADS;
+ if(j==MAX_THREADS-1) {
+ pft_data[j].end=count;
}
-
- //printf("threads created! %d\n",j);
-
- /* join threads */
- for(j=0;j<MAX_THREADS;j++) {
-
- if(j+i==count)
- break;
-
- ret=pthread_join(pft_thread[j],NULL);
- if(ret) {
- perror("[albe fast] pf thread join");
- return ret;
- }
+ else {
+ pft_data[j].end=pft_data[j].start;
+ pft_data[j].end+=count/MAX_THREADS;
}
- /* increment counter */
- i+=MAX_THREADS;
+ ret=pthread_create(&(pft_thread[j]),NULL,
+ potential_force_thread,
+ &(pft_data[j]));
+ if(ret) {
+ perror("[albe fast] pf thread create");
+ return ret;
+ }
+ }
- //printf("threads joined! -> %d\n",i);
+ /* join threads */
+ for(j=0;j<MAX_THREADS;j++) {
+ ret=pthread_join(pft_thread[j],NULL);
+ if(ret) {
+ perror("[albe fast] pf thread join");
+ return ret;
+ }
}
/* some postprocessing */
i);
}
- pthread_exit(NULL);
-
return 0;
}