#include <omp.h>
#endif
-#ifdef PTHREADS
+#if defined PTHREADS || defined VISUAL_THREAD
#include <pthread.h>
#endif
#undef PSE_NAME
#undef PSE_COL
+#ifdef PTHREADS
+/* global mutexes */
+pthread_mutex_t *amutex;
+pthread_mutex_t emutex;
+#endif
+
/*
* the moldyn functions
*/
rand_init(&(moldyn->random),NULL,1);
moldyn->random.status|=RAND_STAT_VERBOSE;
+#ifdef PTHREADS
+ pthread_mutex_init(&emutex,NULL);
+#endif
+
return 0;
}
int moldyn_shutdown(t_moldyn *moldyn) {
+#ifdef PTHREADS
+ int i;
+#endif
+
printf("[moldyn] shutdown\n");
+#ifdef PTHREADS
+ for(i=0;i<moldyn->count;i++)
+ pthread_mutex_destroy(&(amutex[i]));
+ free(amutex);
+ pthread_mutex_destroy(&emutex);
+#endif
+
moldyn_log_shutdown(moldyn);
link_cell_shutdown(moldyn);
rand_close(&(moldyn->random));
void *ptr;
t_atom *atom;
char name[16];
+#ifdef PTHREADS
+ pthread_mutex_t *mutex;
+#endif
new=a*b*c;
count=moldyn->count;
moldyn->atom=ptr;
atom=&(moldyn->atom[count]);
+#ifdef PTHREADS
+ ptr=realloc(amutex,(count+new)*sizeof(pthread_mutex_t));
+ if(!ptr) {
+ perror("[moldyn] mutex realloc (add atom)");
+ return -1;
+ }
+ amutex=ptr;
+ mutex=&(amutex[count]);
+#endif
+
/* no atoms on the boundaries (only reason: it looks better!) */
if(!origin) {
orig.x=0.5*lc;
atom[ret].tag=count+ret;
check_per_bound(moldyn,&(atom[ret].r));
atom[ret].r_0=atom[ret].r;
+#ifdef PTHREADS
+ pthread_mutex_init(&(mutex[ret]),NULL);
+#endif
}
/* update total system mass */
moldyn->lc.subcell->list=ptr;
#endif
+#ifdef PTHREADS
+ ptr=realloc(amutex,(count+1)*sizeof(pthread_mutex_t));
+ if(!ptr) {
+ perror("[moldyn] mutex realloc (add atom)");
+ return -1;
+ }
+ amutex=ptr;
+ pthread_mutex_init(&(amutex[count]),NULL);
+#endif
+
atom=moldyn->atom;
/* initialize new atom */
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) {
}
#endif
+#ifdef PTHREADS
+ printf("##################\n");
+ printf("# USING PTHREADS #\n");
+ printf("##################\n");
+#endif
/* tell the world */
printf("[moldyn] integration start, go get a coffee ...\n");
}
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,
#endif
u8 bc_ij,bc_ik;
int dnlc;
-#ifdef PTHREADS
- int ret;
- pthread_t kthread[27];
- t_kdata kdata[27];
-#endif
count=moldyn->count;
itom=moldyn->atom;
atom=moldyn->atom;
#endif
-#ifdef PTHREADS
- memset(kdata,0,27*sizeof(t_kdata));
-#endif
-
/* reset energy */
moldyn->energy=0.0;
continue;
/* first loop over atoms k */
-#ifndef PTHREADS
if(moldyn->func3b_k1) {
-#endif
for(k=0;k<27;k++) {
if(ktom==&(itom[i]))
continue;
-#ifdef PTHREADS
- kdata[k].moldyn=moldyn;
- kdata[k].ai=&(itom[i]);
- kdata[k].aj=jtom;
- kdata[k].ak=ktom;
- kdata[k].bc=bc_ik;
- ret=pthread_create(&(kthread[k]),NULL,moldyn->func3b_k1,&(kdata[k]));
- if(ret) {
- perror("[moldyn] create k1 thread");
- return ret;
- }
-#else
moldyn->func3b_k1(moldyn,
&(itom[i]),
jtom,
ktom,
bc_ik|bc_ij);
-#endif
#ifdef STATIC_LISTS
}
}
-#ifndef PTHREADS
}
-#endif
if(moldyn->func3b_j2)
moldyn->func3b_j2(moldyn,
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);
}