int hypre_thread_MPI_Allgatherv( void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int *recvcounts, int *displs, MPI_Datatype recvtype, MPI_Comm comm ) { int i,returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&mpi_mtx, unthreaded); if (I_call_mpi) { returnval=MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcounts, displs,recvtype,comm); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
void hypre_SharedFree( char *ptr ) { int unthreaded = pthread_equal(initial_thread, pthread_self()); int I_call_free = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&talloc_mtx, unthreaded); if (I_call_free) { hypre_Free(ptr); } hypre_barrier(&talloc_mtx, unthreaded); }
void hypre_pthread_worker( int threadid ) { void *argptr; hypre_work_proc_t funcptr; pthread_mutex_lock(&hypre_qptr->lock); hypre_qptr->n_working++; while(work_continue) { while (hypre_qptr->n_queue == 0) { if (--hypre_qptr->n_working == 0) pthread_cond_signal(&hypre_qptr->finish_wait); hypre_qptr->n_waiting++; pthread_cond_wait(&hypre_qptr->work_wait, &hypre_qptr->lock); hypre_qptr->n_waiting--; hypre_qptr->n_working++; } hypre_qptr->n_queue--; funcptr = hypre_qptr->worker_proc_queue[hypre_qptr->outp]; argptr = hypre_qptr->argqueue[hypre_qptr->outp]; hypre_qptr->outp = (hypre_qptr->outp + 1) % MAX_QUEUE; pthread_mutex_unlock(&hypre_qptr->lock); (*funcptr)(argptr); hypre_barrier(&worker_mtx, 0); if (work_continue) pthread_mutex_lock(&hypre_qptr->lock); } }
double * hypre_IncrementSharedDataPtr( double *ptr, int size ) { int unthreaded = pthread_equal(initial_thread, pthread_self()); int I_increment = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); if (I_increment) { global_data_ptr = ptr + size; } hypre_barrier(&talloc_mtx, unthreaded); ptr = global_data_ptr; hypre_barrier(&talloc_mtx, unthreaded); return ptr; }
char * hypre_SharedReAlloc( char *ptr, int size ) { int unthreaded = pthread_equal(initial_thread, pthread_self()); int I_call_realloc = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); if (I_call_realloc) { global_alloc_ptr = hypre_ReAlloc( ptr, size ); } hypre_barrier(&talloc_mtx, unthreaded); ptr = global_alloc_ptr; hypre_barrier(&talloc_mtx, unthreaded); return ptr; }
char * hypre_SharedCAlloc( int count, int elt_size ) { char *ptr; int unthreaded = pthread_equal(initial_thread, pthread_self()); int I_call_calloc = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); if (I_call_calloc) { global_alloc_ptr = hypre_CAlloc( count, elt_size ); } hypre_barrier(&talloc_mtx, unthreaded); ptr = global_alloc_ptr; hypre_barrier(&talloc_mtx, unthreaded); return ptr; }
int hypre_thread_MPI_Bcast( void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&mpi_mtx, unthreaded); if (I_call_mpi) { returnval=MPI_Bcast(buffer,count,datatype,root,comm); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
int hypre_thread_MPI_Allreduce( void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&mpi_mtx, unthreaded); if (I_call_mpi) { returnval=MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
int hypre_thread_MPI_Send( void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&mpi_mtx, unthreaded); if (I_call_mpi) { returnval=MPI_Send(buf,count,datatype,dest,tag,comm); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
int hypre_thread_MPI_Recv( void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&mpi_mtx, unthreaded); if (I_call_mpi) { returnval=MPI_Recv(buf,count,datatype,source,tag,comm,status); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
int hypre_thread_MPI_Finalize( ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); hypre_barrier(&mpi_mtx, unthreaded); if (I_call_mpi) { returnval=MPI_Finalize(); } else { returnval=0; } return returnval; }
int hypre_thread_MPI_Barrier( MPI_Comm comm ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); if (I_call_mpi) { returnval=MPI_Barrier(comm); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
int hypre_thread_MPI_Wait( MPI_Request *request, MPI_Status *status ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); if (I_call_mpi) { returnval=MPI_Wait(request,status); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }
int hypre_thread_MPI_Waitall( int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses ) { int returnval; int unthreaded = pthread_equal(initial_thread,pthread_self()); int I_call_mpi = unthreaded || pthread_equal(hypre_thread[0],pthread_self()); if (I_call_mpi) { returnval=MPI_Waitall(count,array_of_requests,array_of_statuses); } else { returnval=0; } hypre_barrier(&mpi_mtx, unthreaded); return returnval; }