#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]));
+ 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 */
*
*/
-/* helper / special functions */
-
-#ifdef PTHREADS
-void *write_save_file(void *ptr) {
-
- int fd;
- char dir[128];
- t_moldyn *moldyn;
-
- moldyn=ptr;
-
- snprintf(dir,128,"%s/s-%08.f.save",moldyn->vlsdir,moldyn->time);
- fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,S_IRUSR|S_IWUSR);
- if(fd<0) perror("[moldyn] save fd open");
- else {
- write(fd,moldyn,sizeof(t_moldyn));
- write(fd,moldyn->atom,moldyn->count*sizeof(t_atom));
- }
-
- close(fd);
-
- pthread_exit(NULL);
-
- return 0;
-}
-#endif
-
/* start the integration */
int moldyn_integrate(t_moldyn *moldyn) {
t_3dvec momentum;
t_moldyn_schedule *sched;
t_atom *atom;
-#ifndef PTHREADS
int fd;
char dir[128];
-#endif
double ds;
double energy_scale;
struct timeval t1,t2;
}
if(s) {
if(!(moldyn->total_steps%s)) {
+ snprintf(dir,128,"%s/s-%08.f.save",
+ moldyn->vlsdir,moldyn->time);
+ fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,
+ S_IRUSR|S_IWUSR);
+ if(fd<0) perror("[moldyn] save fd open");
+ else {
+ write(fd,moldyn,sizeof(t_moldyn));
+ write(fd,moldyn->atom,
+ moldyn->count*sizeof(t_atom));
+ }
+ close(fd);
+ }
+ }
+ if(a) {
+ if(!(moldyn->total_steps%a)) {
#ifdef PTHREADS
/* check whether thread has not terminated yet */
if(!first) {
md_copy.atom=atom_copy;
memcpy(atom_copy,moldyn->atom,moldyn->count*sizeof(t_atom));
change=0;
- ret=pthread_create(&io_thread,NULL,write_save_file,&md_copy);
+ ret=pthread_create(&io_thread,NULL,visual_atoms,&md_copy);
if(ret) {
- perror("[moldyn] create save file thread\n");
+ perror("[moldyn] create visual atoms thread\n");
return -1;
}
#else
- snprintf(dir,128,"%s/s-%08.f.save",
- moldyn->vlsdir,moldyn->time);
- fd=open(dir,O_WRONLY|O_TRUNC|O_CREAT,
- S_IRUSR|S_IWUSR);
- if(fd<0) perror("[moldyn] save fd open");
- else {
- write(fd,moldyn,sizeof(t_moldyn));
- write(fd,moldyn->atom,
- moldyn->count*sizeof(t_atom));
- }
- close(fd);
-#endif
- }
- }
- if(a) {
- if(!(moldyn->total_steps%a)) {
visual_atoms(moldyn);
+#endif
}
}
jtom,
ktom,
bc_ik|bc_ij);
+
#ifdef STATIC_LISTS
}
#elif LOWMEM_LISTS
return 0;
}
+#ifdef PTHREADS
+void *visual_atoms(void *ptr) {
+#else
int visual_atoms(t_moldyn *moldyn) {
+#endif
int i;
char file[128+64];
t_visual *v;
t_atom *atom;
t_vb vb;
+#ifdef PTHREADS
+ t_moldyn *moldyn;
+
+ moldyn=ptr;
+#endif
v=&(moldyn->vis);
dim.x=v->dim.x;
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
return -1;
+#endif
}
/* write the actual data file */
close(vb.fd);
+#ifdef PTHREADS
+ pthread_exit(NULL);
+
+}
+#else
+
return 0;
}
+#endif
/*
* fpu cntrol functions