/* initialize vmdcon */ void vmdcon_init(void) { wkf_mutex_init(&vmdcon_status_lock); wkf_mutex_init(&vmdcon_output_lock); vmdcon_set_status(VMDCON_NONE, NULL); }
// setup and launch bond search threads int vmd_bondsearch_thr(const float *pos, const float *radii, GridSearchPairlist * head, int totb, int **boxatom, int *numinbox, int **nbrlist, int maxpairs, float pairdist) { int i; bondsearchthrparms *parms; wkf_thread_t * threads; wkf_mutex_t pairlistmutex; ///< guards pairlist wkf_mutex_init(&pairlistmutex); // init mutex before use int numprocs = wkf_thread_numprocessors(); /* allocate array of threads */ threads = (wkf_thread_t *) calloc(numprocs * sizeof(wkf_thread_t), 1); /* allocate and initialize array of thread parameters */ parms = (bondsearchthrparms *) malloc(numprocs * sizeof(bondsearchthrparms)); for (i=0; i<numprocs; i++) { parms[i].threadid = i; parms[i].threadcount = numprocs; parms[i].pairlistmutex = &pairlistmutex; parms[i].head = NULL; parms[i].pos = (float *) pos; parms[i].radii = (float *) radii; parms[i].totb = totb; parms[i].boxatom = boxatom; parms[i].numinbox = numinbox; parms[i].nbrlist = nbrlist; parms[i].maxpairs = maxpairs; parms[i].pairdist = pairdist; } #if defined(VMDTHREADS) /* spawn child threads to do the work */ for (i=0; i<numprocs; i++) { wkf_thread_create(&threads[i], bondsearchthread, &parms[i]); } /* join the threads after work is done */ for (i=0; i<numprocs; i++) { wkf_thread_join(threads[i], NULL); } #else bondsearchthread(&parms[0]); // single-threaded code #endif // assemble final pairlist from sublists for (i=0; i<numprocs; i++) { if (parms[i].head != NULL) { GridSearchPairlist *tmp = head->next; head->next = parms[i].head; parms[i].head->next = tmp; } } wkf_mutex_destroy(&pairlistmutex); // destroy mutex when finished /* free thread parms */ free(parms); free(threads); return 0; }