#include "nbc.h" /* Dissemination implementation of MPI_Ibarrier */ int NBC_Ibarrier(MPI_Comm comm, NBC_Handle* handle) { int round, rank, p, maxround, res, recvpeer, sendpeer; NBC_Schedule *schedule; res = NBC_Init_handle(handle, comm); if(res != NBC_OK) { printf("Error in NBC_Init_handle(%i)\n", res); return res; } res = MPI_Comm_rank(comm, &rank); if (MPI_SUCCESS != res) { printf("MPI Error in MPI_Comm_rank() (%i)\n", res); return res; } res = MPI_Comm_size(comm, &p); if (MPI_SUCCESS != res) { printf("MPI Error in MPI_Comm_size() (%i)\n", res); return res; } handle->tmpbuf=NULL; #ifdef NBC_CACHE_SCHEDULE /* there only one argument set per communicator -> hang it directly at * the tree-position, NBC_Dict_size[...] is 0 for not initialized and * 1 for initialized. NBC_Dict[...] is a pointer to the schedule in * this case */ if(handle->comminfo->NBC_Dict_size[NBC_BARRIER] == 0) { /* we did not init it yet */ #endif schedule = malloc(sizeof(NBC_Schedule)); if (NULL == schedule) { printf("Error in malloc()\n"); return res; } round = -1; res = NBC_Sched_create(schedule); if(res != NBC_OK) { printf("Error in NBC_Sched_create (%i)\n", res); return res; } maxround = (int)ceil((log(p)/LOG2)-1); do { round++; sendpeer = (rank + (1<comminfo->NBC_Dict[NBC_BARRIER] = (hb_tree*)schedule; handle->comminfo->NBC_Dict_size[NBC_BARRIER] = 1; } else { /* we found it */ schedule = (NBC_Schedule*)handle->comminfo->NBC_Dict[NBC_BARRIER]; } #endif res = NBC_Start(handle, schedule); if (NBC_OK != res) { printf("Error in NBC_Start() (%i)\n", res); return res; } return NBC_OK; } /*void NBC_IBARRIER(MPI_Fint *comm, MPI_Fint *ierr) { *ierr = NBC_Ibarrier(MPI_Comm comm, NBC_Handle* handle); }*/