PETSC_EXTERN_C void MPIAPI PetscSplitReduction_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscScalar *xin = (PetscScalar *)in,*xout = (PetscScalar*)out; PetscInt i,count = (PetscInt)*cnt; PetscFunctionBegin; if (*datatype != MPIU_REAL) { (*PetscErrorPrintf)("Can only handle MPIU_REAL data types"); MPI_Abort(MPI_COMM_SELF,1); } #if defined(PETSC_USE_COMPLEX) count = count/2; #endif count = count/2; for (i=0; i<count; i++) { if (((int)PetscRealPart(xin[count+i])) == REDUCE_SUM) { /* second half of xin[] is flags for reduction type */ xout[i] += xin[i]; } else if ((PetscInt)PetscRealPart(xin[count+i]) == REDUCE_MAX) { xout[i] = PetscMax(*(PetscReal *)(xout+i),*(PetscReal *)(xin+i)); } else if ((PetscInt)PetscRealPart(xin[count+i]) == REDUCE_MIN) { xout[i] = PetscMin(*(PetscReal *)(xout+i),*(PetscReal *)(xin+i)); } else { (*PetscErrorPrintf)("Reduction type input is not REDUCE_SUM, REDUCE_MAX, or REDUCE_MIN"); MPI_Abort(MPI_COMM_SELF,1); } } PetscFunctionReturnVoid(); }
static void update_omega(PetscReal *omega,PetscReal *omega_old,PetscInt j,PetscReal *alpha,PetscReal *beta,PetscReal eps1,PetscReal anorm) { PetscInt k; PetscReal T,binv; PetscFunctionBegin; /* Estimate of contribution to roundoff errors from A*v fl(A*v) = A*v + f, where ||f|| \approx eps1*||A||. For a full matrix A, a rule-of-thumb estimate is eps1 = sqrt(n)*eps */ T = eps1*anorm; binv = 1.0/beta[j+1]; /* Update omega(1) using omega(0)==0 */ omega_old[0]= beta[1]*omega[1] + (alpha[0]-alpha[j])*omega[0] - beta[j]*omega_old[0]; if (omega_old[0] > 0) omega_old[0] = binv*(omega_old[0] + T); else omega_old[0] = binv*(omega_old[0] - T); /* Update remaining components */ for (k=1;k<j-1;k++) { omega_old[k] = beta[k+1]*omega[k+1] + (alpha[k]-alpha[j])*omega[k] + beta[k]*omega[k-1] - beta[j]*omega_old[k]; if (omega_old[k] > 0) omega_old[k] = binv*(omega_old[k] + T); else omega_old[k] = binv*(omega_old[k] - T); } omega_old[j-1] = binv*T; /* Swap omega and omega_old */ for (k=0;k<j;k++) { omega[k] = omega_old[k]; omega_old[k] = omega[k]; } omega[j] = eps1; PetscFunctionReturnVoid(); }
static void OnPaint_Win32(HWND hWnd) { PAINTSTRUCT ps; HDC hdc; WindowNode current = NULL; PetscFunctionBegin; InvalidateRect(hWnd,NULL,TRUE); WaitForSingleObject(g_hWindowListMutex, INFINITE); current = WindowListHead; hdc = BeginPaint(hWnd, &ps); while (current != NULL) { if (current->hWnd == hWnd) { /* flushes primary buffer to window */ BitBlt(hdc,0,0,GetDeviceCaps(hdc,HORZRES),GetDeviceCaps(hdc,VERTRES), current->Buffer,0,0,SRCCOPY); /* StretchBlt(hdc,0,0,w,h, current->Buffer,0,0,current->bitwidth,current->bitheight,SRCCOPY); */ break; } current = current->wnext; } EndPaint(hWnd, &ps); ReleaseMutex(g_hWindowListMutex); PetscFunctionReturnVoid(); }
void MessageLoopThread_Win32(PetscDraw draw) { PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data; MSG msg; HWND hWnd = NULL; char classname[MAX_LOADSTRING + 1]; WNDCLASSEX wclass; LPVOID lpMsgBuf; PetscFunctionBegin; /* initialize window class parameters */ wclass.cbSize = sizeof(WNDCLASSEX); wclass.style = CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW; wclass.lpfnWndProc = (WNDPROC)PetscWndProc; wclass.cbClsExtra = 0; wclass.cbWndExtra = 0; wclass.hInstance = NULL; wclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wclass.hCursor = LoadCursor(NULL,IDC_ARROW); wclass.hbrBackground = GetStockBrush(WHITE_BRUSH); wclass.lpszMenuName = NULL; wclass.lpszClassName = classname; wclass.hIconSm = NULL; RegisterClassEx(&wclass); hWnd = CreateWindowEx(0, classname, NULL, WS_OVERLAPPEDWINDOW, draw->x, draw->y, draw->w, draw->h, NULL, NULL, hInst, NULL); if (!hWnd) { lpMsgBuf = (LPVOID)"Window Not Succesfully Created"; MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); LocalFree( lpMsgBuf ); exit(0); } windraw->hWnd = hWnd; /* display and update new window */ ShowWindow(hWnd,SW_SHOWNORMAL); UpdateWindow(hWnd); SetEvent(windraw->hReadyEvent); while (GetMessage(&msg,hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } PetscFunctionReturnVoid(); }
static void CholmodErrorHandler(int status,const char *file,int line,const char *message) { PetscFunctionBegin; if (status > CHOLMOD_OK) { PetscInfo4(static_F,"CHOLMOD warning %d at %s:%d: %s",status,file,line,message); } else if (status == CHOLMOD_OK) { /* Documentation says this can happen, but why? */ PetscInfo3(static_F,"CHOLMOD OK at %s:%d: %s",file,line,message); } else { PetscErrorPrintf("CHOLMOD error %d at %s:%d: %s\n",status,file,line,message); } PetscFunctionReturnVoid(); }
PETSC_EXTERN void MPIAPI PetscMaxSum_Local(void *in,void *out,int *cnt,MPI_Datatype *datatype) { PetscInt *xin = (PetscInt*)in,*xout = (PetscInt*)out,i,count = *cnt; PetscFunctionBegin; if (*datatype != MPIU_2INT) { (*PetscErrorPrintf)("Can only handle MPIU_2INT data types"); MPI_Abort(MPI_COMM_WORLD,1); } for (i=0; i<count; i++) { xout[2*i] = PetscMax(xout[2*i],xin[2*i]); xout[2*i+1] += xin[2*i+1]; } PetscFunctionReturnVoid(); }
static void MPIAPI MPIU_MaxIndex_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out; PetscFunctionBegin; if (*datatype != MPIU_REAL) { (*PetscErrorPrintf)("Can only handle MPIU_REAL data types"); MPI_Abort(MPI_COMM_SELF,1); } if (xin[0] > xout[0]) { xout[0] = xin[0]; xout[1] = xin[1]; } else if (xin[0] == xout[0]) { xout[1] = PetscMin(xin[1],xout[1]); } PetscFunctionReturnVoid(); /* cannot return a value */ }
PETSC_EXTERN void MPIAPI PetscADMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscScalar *xin = (PetscScalar*)in,*xout = (PetscScalar*)out; PetscInt i,count = *cnt; PetscFunctionBegin; if (*datatype != MPIU_2SCALAR) { (*PetscErrorPrintf)("Can only handle MPIU_2SCALAR data (i.e. double or complex) types"); MPI_Abort(MPI_COMM_WORLD,1); } for (i=0; i<count; i++) { if (PetscRealPart(xout[2*i]) > PetscRealPart(xin[2*i])) { xout[2*i] = xin[2*i]; xout[2*i+1] = xin[2*i+1]; } } PetscFunctionReturnVoid(); }
EXTERN_C_BEGIN #undef __FUNCT__ #define __FUNCT__ "VecMax_Local" void PETSCVEC_DLLEXPORT MPIAPI VecMax_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscReal *xin = (PetscReal *)in,*xout = (PetscReal*)out; PetscFunctionBegin; if (*datatype != MPIU_REAL) { (*PetscErrorPrintf)("Can only handle MPIU_REAL data types"); MPI_Abort(MPI_COMM_WORLD,1); } if (xin[0] > xout[0]) { xout[0] = xin[0]; xout[1] = xin[1]; } else if (xin[0] == xout[0]) { xout[1] = PetscMin(xin[1],xout[1]); } PetscFunctionReturnVoid(); /* cannot return a value */ }
PETSC_EXTERN void PetscSum_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscInt i,count = *cnt; PetscFunctionBegin; if (*datatype == MPIU_REAL) { PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out; for (i=0; i<count; i++) xout[i] += xin[i]; } #if defined(PETSC_HAVE_COMPLEX) else if (*datatype == MPIU_COMPLEX) { PetscComplex *xin = (PetscComplex*)in,*xout = (PetscComplex*)out; for (i=0; i<count; i++) xout[i] += xin[i]; } #endif else { (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_COMPLEX data types"); MPI_Abort(MPI_COMM_WORLD,1); } PetscFunctionReturnVoid(); }
static void compute_int(PetscBool *which,PetscReal *mu,PetscInt j,PetscReal delta,PetscReal eta) { PetscInt i,k,maxpos; PetscReal max; PetscBool found; PetscFunctionBegin; /* initialize which */ found = PETSC_FALSE; maxpos = 0; max = 0.0; for (i=0;i<j;i++) { if (PetscAbsReal(mu[i]) >= delta) { which[i] = PETSC_TRUE; found = PETSC_TRUE; } else which[i] = PETSC_FALSE; if (PetscAbsReal(mu[i]) > max) { maxpos = i; max = PetscAbsReal(mu[i]); } } if (!found) which[maxpos] = PETSC_TRUE; for (i=0;i<j;i++) { if (which[i]) { /* find left interval */ for (k=i;k>=0;k--) { if (PetscAbsReal(mu[k])<eta || which[k]) break; else which[k] = PETSC_TRUE; } /* find right interval */ for (k=i+1;k<j;k++) { if (PetscAbsReal(mu[k])<eta || which[k]) break; else which[k] = PETSC_TRUE; } } } PetscFunctionReturnVoid(); }
EXTERN_C_END EXTERN_C_BEGIN #undef __FUNCT__ #define __FUNCT__ "VecMin_Local" void MPIAPI VecMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscReal *xin = (PetscReal *)in,*xout = (PetscReal*)out; PetscFunctionBegin; if (*datatype != MPIU_REAL) { (*PetscErrorPrintf)("Can only handle MPIU_REAL data types"); MPI_Abort(MPI_COMM_SELF,1); } if (xin[0] < xout[0]) { xout[0] = xin[0]; xout[1] = xin[1]; } else if (xin[0] == xout[0]) { xout[1] = PetscMin(xin[1],xout[1]); } PetscFunctionReturnVoid(); }
PETSC_EXTERN void PetscMin_Local(void *in,void *out,PetscMPIInt *cnt,MPI_Datatype *datatype) { PetscInt i,count = *cnt; PetscFunctionBegin; if (*datatype == MPIU_REAL) { PetscReal *xin = (PetscReal*)in,*xout = (PetscReal*)out; for (i=0; i<count; i++) xout[i] = PetscMin(xout[i],xin[i]); } #if defined(PETSC_HAVE_COMPLEX) else if (*datatype == MPIU_COMPLEX) { PetscComplex *xin = (PetscComplex*)in,*xout = (PetscComplex*)out; for (i=0; i<count; i++) { xout[i] = PetscRealPartComplex(xout[i])>PetscRealPartComplex(xin[i]) ? xin[i] : xout[i]; } } #endif else { (*PetscErrorPrintf)("Can only handle MPIU_REAL or MPIU_SCALAR data (i.e. double or complex) types"); MPI_Abort(MPI_COMM_WORLD,1); } PetscFunctionReturnVoid(); }
static void OnDestroy_Win32(HWND hWnd) { /* searches linked list of window data and frees corresponding memory */ WindowNode current; PetscFunctionBegin; WaitForSingleObject(g_hWindowListMutex, INFINITE); current = WindowListHead; SetEvent(current->event); while (current != NULL) { if (current->hWnd == hWnd) { if (current->wprev != NULL) current->wprev->wnext = current->wnext; else WindowListHead = current->wnext; if (current->MouseListHead) deletemouselist_Win32(current); else PetscFree(current); break; } current = current->wnext; } ReleaseMutex(g_hWindowListMutex); PostQuitMessage(0); PetscFunctionReturnVoid(); }
void PopMessageLoopThread_Win32(PetscDraw popdraw) { PetscDraw_Win32 *pop = (PetscDraw_Win32*)popdraw->data; MSG msg; HWND hWnd = NULL; char PopClassName [MAX_LOADSTRING + 1]; RECT r; int width,height; WNDCLASSEX myclass; LPVOID lpMsgBuf; PetscFunctionBegin; /* initialize window class parameters */ myclass.cbSize = sizeof(WNDCLASSEX); myclass.style = CS_OWNDC; myclass.lpfnWndProc = (WNDPROC)PetscWndProc; myclass.cbClsExtra = 0; myclass.cbWndExtra = 0; myclass.hInstance = NULL; myclass.hIcon = NULL; myclass.hCursor = LoadCursor(NULL, IDC_ARROW); myclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); myclass.lpszMenuName = NULL; myclass.lpszClassName = PopClassName; myclass.hIconSm = NULL; RegisterClassEx(&myclass); SetRect(&r,0,0,450,450); width = (r.right - r.left) / 3; height = (r.bottom - r.top) / 3; hWnd = CreateWindowEx(0, PopClassName, NULL, WS_POPUPWINDOW | WS_CAPTION, 0,0, width,height, NULL, NULL, hInst, NULL); pop->x = 0; pop->y = 0; pop->w = width; pop->h = height; if(!hWnd) { lpMsgBuf = (LPVOID)"Window Not Succesfully Created"; MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); LocalFree( lpMsgBuf ); exit(0); } pop->hWnd = hWnd; /* display and update new popup window */ ShowWindow(pop->hWnd, SW_SHOWNORMAL); UpdateWindow(pop->hWnd); SetEvent(pop->hReadyEvent); while (GetMessage(&msg, pop->hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } PetscFunctionReturnVoid(); }