#include <omp.h>
#endif
-#ifdef PTHREADS
+#if defined PTHREADS || defined VISUAL_THREAD
#include <pthread.h>
#endif
struct timeval t1,t2;
//double tp;
-#ifdef PTHREADS
+#ifdef VISUAL_THREAD
u8 first,change;
pthread_t io_thread;
int ret;
moldyn->debug=0;
/* zero & init moldyn copy */
-#ifdef PTHREADS
+#ifdef VISUAL_THREAD
memset(&md_copy,0,sizeof(t_moldyn));
atom_copy=malloc(moldyn->count*sizeof(t_atom));
if(atom_copy==NULL) {
}
if(a) {
if(!(moldyn->total_steps%a)) {
-#ifdef PTHREADS
+#ifdef VISUAL_THREAD
/* check whether thread has not terminated yet */
if(!first) {
ret=pthread_join(io_thread,NULL);
/* get current time */
gettimeofday(&t2,NULL);
-printf("\rsched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)",
+printf("sched:%d, steps:%d/%d, T:%4.1f/%4.1f P:%4.1f/%4.1f V:%6.1f (%d)\n",
sched->count,i,moldyn->total_steps,
moldyn->t,moldyn->t_avg,
moldyn->p/BAR,moldyn->p_avg/BAR,
return 0;
}
-#ifdef PTHREADS
+#ifdef VISUAL_THREAD
void *visual_atoms(void *ptr) {
#else
int visual_atoms(t_moldyn *moldyn) {
t_visual *v;
t_atom *atom;
t_vb vb;
-#ifdef PTHREADS
+#ifdef VISUAL_THREAD
t_moldyn *moldyn;
moldyn=ptr;
vb.fd=open(file,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR);
if(vb.fd<0) {
perror("open visual save file fd");
-#ifndef PTHREADS
+#ifndef VISUAL_THREAD
return -1;
#endif
}
atom[i].ekin);
// bonds between atoms
+#ifndef VISUAL_THREAD
process_2b_bonds(moldyn,&vb,visual_bonds_process);
+#endif
// boundaries
if(dim.x) {
close(vb.fd);
-#ifdef PTHREADS
+#ifdef VISUAL_THREAD
pthread_exit(NULL);
}
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;
}