void Signal::send() { SafeCall(SetEvent(mEventHandle)); }
Signal::~Signal() { SafeCall(CloseHandle(mEventHandle)); mEventHandle = NULL; }
void Matrix::transpose() { SafeCall(igraph_matrix_transpose(ptr())); }
LRESULT CALLBACK WindowProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { const int borderedge = 0; // 8; const int topspace = 0; static HWND hwndScintilla = 0; HWND hWnd = 0; char *szBuffer = 0; RECT rect; static UINT_PTR tid = 0; switch (message) { case WM_INITDIALOG: case WM_CREATE: exitpending = false; ::GetClientRect(hwndDlg, &rect); { HMENU hMenu = (HMENU)::LoadMenu(ghModule, MAKEINTRESOURCE(IDR_CONSOLEMENU)); if (hMenu != INVALID_HANDLE_VALUE){ ::SetMenu(hwndDlg, hMenu); DWORD dw; if (CRegistryUtils::GetRegDWORD(HKEY_CURRENT_USER, &dw, REGISTRY_KEY, REGISTRY_VALUE_CONSOLE_ON_TOP) && dw) { CheckMenuItem( hMenu, ID_CONSOLE_ALWAYSONTOP , MF_CHECKED ); } } } hwndScintilla = CreateWindowExA(0, "Scintilla", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN, borderedge, borderedge + topspace, rect.right - 2 * borderedge, rect.bottom - 2 * borderedge - topspace, hwndDlg, 0, ghModule, NULL); if (hwndScintilla) { lpfnEditWndProc = (WNDPROC)SetWindowLongPtr(hwndScintilla, GWLP_WNDPROC, (LONG_PTR)SubClassProc); ::SetFocus(hwndScintilla); fn = (sptr_t(__cdecl *)(sptr_t*, int, uptr_t, sptr_t))SendMessage(hwndScintilla, SCI_GETDIRECTFUNCTION, 0, 0); ptr = (sptr_t*)SendMessage(hwndScintilla, SCI_GETDIRECTPOINTER, 0, 0); char buffer[64]; DWORD dw; fn(ptr, SCI_SETCODEPAGE, SC_CP_UTF8, 0); SetConsoleDefaults(); fn(ptr, SCI_SETMARGINWIDTHN, 1, 0); std::list< std::string > loglist; getLogText(loglist); for (std::list< std::string >::iterator iter = loglist.begin(); iter != loglist.end(); iter++) { if (!strncmp(iter->c_str(), DEFAULT_PROMPT, 2) || !strncmp(iter->c_str(), CONTINUATION_PROMPT, 2)) { AppendLog(iter->c_str(), 0, 0); } else AppendLog(iter->c_str(), 1, 0); } Prompt(); //if (!wlInit) initWordList(); tid = ::SetTimer(hwndDlg, TIMERID_FLUSHBUFFER, 1000, TimerProc); } else { DWORD dwErr = ::GetLastError(); char sz[64]; sprintf_s(sz, 64, "FAILED: 0x%x", dwErr); OutputDebugStringA(sz); ::MessageBoxA(0, sz, "ERR", MB_OK); EndDialog(hwndDlg, IDCANCEL); return TRUE; } hWndConsole = hwndDlg; if (rectConsole.right == rectConsole.left) { ::SetWindowPos(hwndDlg, HWND_TOP, 0, 0, 600, 400, SWP_NOZORDER); } else { ::SetWindowPos(hwndDlg, HWND_TOP, rectConsole.left, rectConsole.top, rectConsole.right - rectConsole.left, rectConsole.bottom - rectConsole.top, SWP_NOZORDER); } break; case WM_SIZE: case WM_WINDOWPOSCHANGED: case WM_SIZING: ::GetClientRect(hwndDlg, &rect); ::SetWindowPos(hwndScintilla, HWND_TOP, borderedge, borderedge + topspace, rect.right - 2 * borderedge, rect.bottom - 2 * borderedge - topspace, SWP_NOMOVE | SWP_NOZORDER | SWP_DEFERERASE); if ( message == WM_SIZE ) UpdateConsoleWidth(); break; case WM_ERASEBKGND: break; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case SCN_MODIFIED: // what am I trapping this for? // A: was thinking about handling PASTE { // SCNotification *scn = (SCNotification*)lParam; // DebugOut("Modified: 0x%x\n", scn->modificationType); } case SCN_CHARADDED: { SCNotification *scn = (SCNotification*)lParam; // DebugOut("CA: %x\n", scn->ch); // I think because I switched to utf-8 I'm gettings // double notifications if (scn->ch) testAutocomplete(); } break; } break; case WM_SETFOCUS: ::SetFocus(hwndScintilla); break; case WM_APPEND_LOG: AppendLog((const char*)lParam); break; case WM_DESTROY: ::GetWindowRect(hwndDlg, &rectConsole); if (tid) { ::KillTimer(hwndDlg, tid); tid = 0; } hWndConsole = 0; ::PostQuitMessage(0); break; case WM_CALL_COMPLETE: CallComplete((PARSE_STATUS_2)wParam, lParam); break; case WM_COMMAND: switch (LOWORD(wParam)) { case WM_CLEAR_BUFFER: case ID_CONSOLE_CLEARHISTORY: ClearHistory(); break; case ID_CONSOLE_INSTALLPACKAGES: SafeCall(SCC_INSTALLPACKAGES, 0, 0); break; case ID_CONSOLE_HOMEDIRECTORY: BERT_HomeDirectory(); break; case ID_CONSOLE_RELOADSTARTUPFILE: SafeCall(SCC_RELOAD_STARTUP, 0, 0); break; case WM_REBUILD_WORDLISTS: initWordList(); break; case ID_CONSOLE_CONSOLEOPTIONS: ConsoleOptions(hwndDlg); break; case ID_CONSOLE_ALWAYSONTOP: ToggleOnTop(hwndDlg); reopenWindow = true; ::SetFocus(hWndExcel); ShowWindow(hwndDlg, SW_HIDE); ::PostMessage(hwndDlg, WM_DESTROY, 0, 0); break; // this message is used in case the close console command // is called interactively; in that event we will be in the middle // of a COM call and we don't want to break here. wait until the // call is complete. if it's called some other way (such as from // excel, which it should not be), then you can close. case WM_CLOSE_CONSOLE_ASYNC: if (inputlock) { exitpending = true; break; } case ID_CONSOLE_CLOSECONSOLE: case WM_CLOSE_CONSOLE: case IDOK: case IDCANCEL: ::GetWindowRect(hwndDlg, &rectConsole); if (tid) { ::KillTimer(hwndDlg, tid); tid = 0; } EndDialog(hwndDlg, wParam); ::CloseWindow(hwndDlg); hWndConsole = 0; ::PostQuitMessage(0); return TRUE; } break; } return DefWindowProc(hwndDlg, message, wParam, lParam); return FALSE; }
Matrix &Matrix::operator-=(const Matrix &matrix) { SafeCall(igraph_matrix_sub(ptr(), matrix.ptr())); return *this; }
Vector Matrix::rowsums() const { Vector vector(ncol()); SafeCall(igraph_matrix_rowsum(ptr(), vector.ptr())); return vector; }
EdgeSelector::EdgeSelector(const EdgeSelector &es) { SafeCall(igraph_es_copy(ptr(), es.ptr())); }
void GiGraphics::_setCanvas(GiCanvas* canvas) { m_impl->canvas = canvas; SafeCall(m_impl->canvas, _init(this, m_impl)); }
EdgeIterator::EdgeIterator(const Graph &graph, const EdgeSelector &es) { SafeCall(igraph_eit_create(graph.ptr(), es.es(), ptr())); }
int main(int argc, char ** argv){ int i; if( (argc>=2) && (atoi(argv[1])!=RANK)) error("rank %d mandatory",RANK); printf("CUDA RANK=%d\n",RANK); kernel.print(); // build busylist busylist = (uint32_t*)malloc_file(CNK*sizeof(uint32_t),FMODE_RO,BLIST_FORMAT,RANK); // put busylist SafeCall(cuMemHostRegister(busylist,CNK*sizeof*busylist,CU_MEMHOSTREGISTER_DEVICEMAP)); SafeCall(cuMemHostGetDevicePointer(&host_busylist,busylist,0)); SafeCall(cuModuleGetGlobal(&dev_busylist,&bytes,kernel.module[0].module,"busylist")); if(bytes!=sizeof(host_busylist)) error("busylist!"); SafeCall(cuMemcpyHtoD(dev_busylist,&host_busylist,bytes)); // put array #ifdef IN_mk_data mkdir(DATADIR,0755); errno=0; array = (unsigned char *)malloc_file(abytes(RANK,CNK),1,DATADIR"%d",RANK); #else array = (unsigned char *)malloc_file(abytes(RANK,CNK),0,DATADIR"%d",RANK); #endif SafeCall(cuMemHostRegister(array,abytes(RANK,CNK),CU_MEMHOSTREGISTER_DEVICEMAP)); SafeCall(cuMemHostGetDevicePointer(&host_array,array,0)); SafeCall(cuModuleGetGlobal(&dev_array,&bytes,kernel.module[0].module,"array")); if(bytes!=sizeof(host_array)) error("array!"); SafeCall(cuMemcpyHtoD(dev_array,&host_array,bytes)); #define THREADS 512 #define MAXG 65535 uint64_t nado = (cnk[RANK] +(THREADS-1))/THREADS; uint32_t gridx = nado>MAXG?MAXG:nado; uint32_t gridy = (nado+(MAXG-1))/MAXG; printf("gridy=%d gridx=%d THREAD=%d\n",gridy, gridx, THREADS); kernel.launch(params,THREADS,gridx,gridy); kernel.wait(); SafeCall(cuMemHostUnregister(busylist)); SafeCall(cuMemHostUnregister(array)); SafeCall(cuModuleGetGlobal(&dev_changed,&bytes,kernel.module[0].module,"changed")); if(bytes!=sizeof(changed)) error("changed!"); SafeCall(cuMemcpyDtoH(changed,dev_changed,bytes)); for(i=0;i<CACHESIZE;i++) total += changed[i]; printf("changed=%ju\n",total); return 0; }
void CMainFrame::OnDestroy() { SafeCall(m_paneLayout, DestroyPanes()); Object<IUIOptions>(clsidUIOptions)->save(); }
void CMainFrame::OnClose() { SaveCommandBars(); SafeCall(m_paneLayout, SaveDockingPanes()); }
void testAutocomplete() { int len = fn(ptr, SCI_GETCURLINE, 0, 0); if (len <= 2) return; char *c = new char[len + 1]; int caret = fn(ptr, SCI_GETCURLINE, len + 1, (sptr_t)c); std::string part; static std::string lastList; // FOR NOW, require that caret is at eol if (caret == len - 1) { bool money = false; for (--caret; caret >= 2 && isWordChar(c[caret]); caret--){ if (c[caret] == '$' || c[caret] == '@') money = true; } caret++; int slen = strlen(&(c[caret])); if (slen > 1) { std::string str = &(c[caret]); if (money) { std::string token = ""; int midx = 0; for (int i = 1; i < slen; i++) if (str[i] == '$' || str[i] == '@') midx = i ; if (midx > 0) token = std::string(str.begin(), str.begin() + midx); if (token.compare(moneyToken)) { int sc; moneyList.clear(); moneyList.reserve(100); std::vector< std::string > sv; sv.push_back(token); SafeCall(SCC_NAMES, &sv, &sc); moneyToken = token; } } SVECTOR::iterator iter = std::lower_bound(money ? moneyList.begin() : wordList.begin(), money ? moneyList.end() : wordList.end(), str); c[len - 2]++; str = &(c[caret]); SVECTOR::iterator iter2 = std::lower_bound(money ? moneyList.begin() : wordList.begin(), money ? moneyList.end() : wordList.end(), str); int count = iter2 - iter; str = ""; if (count > 0 && count <= MAX_AUTOCOMPLETE_LIST_LEN) { DebugOut("count %d\n", count); for (count = 0; iter < iter2; iter++, count++) { if (count) str += " "; str += iter->c_str(); } if ( !fn(ptr, SCI_AUTOCACTIVE, 0, 0 ) || lastList.compare(str)) fn(ptr, SCI_AUTOCSHOW, slen, (sptr_t)(str.c_str())); lastList = str; } } } // TODO: optimize this over a single bit of typing... caret = fn(ptr, SCI_GETCURLINE, len + 1, (sptr_t)c); std::string sc(c, c + caret); static std::string empty = ""; static std::regex bparen("\\([^\\(]*?\\)"); static std::regex rex("[^\\w\\._\\$]([\\w\\._\\$]+)\\s*\\([^\\)\\(]*$"); static std::string lasttip; while (std::regex_search(sc, bparen)) sc = regex_replace(sc, bparen, empty); std::smatch mat; bool ctvisible = fn(ptr, SCI_CALLTIPACTIVE, 0, 0); // so there is the possibility that we have a tip because we're in one // function, but then we close the tip and fall into an enclosing // function... actually my regex doesn't work, then. if (std::regex_search(sc, mat, rex) /* && !ctvisible */) { std::string tip; std::string sym(mat[1].first, mat[1].second); if (sym.compare(lasttip)) { int sc = 0; std::vector< std::string > sv; sv.push_back(sym); SafeCall(SCC_CALLTIP, &sv, &sc); tip = calltip; // if(0)// (getCallTip(tip, sym)) if (sc) { DebugOut("%s: %s\n", sym.c_str(), tip.c_str()); int pos = fn(ptr, SCI_GETCURRENTPOS, 0, 0); // pos -= caret; // start of line pos -= (mat[0].second - mat[0].first - 1); // this is not correct b/c we are munging the string fn(ptr, SCI_CALLTIPSHOW, pos, (sptr_t)tip.c_str()); } else if (ctvisible) fn(ptr, SCI_CALLTIPCANCEL, 0, 0); lasttip = sym; } } else { if (ctvisible) fn(ptr, SCI_CALLTIPCANCEL, 0, 0); lasttip = ""; } delete[] c; }
void GiGraphics::clearCachedBitmap() { SafeCall(m_impl->canvas, clearCachedBitmap()); }
EdgeSelector::EdgeSelector(std::initializer_list<double> list) { Vector vector(list); SafeCall(igraph_es_vector_copy(ptr(), vector.ptr())); }
void GiGraphics::setAntiAliasMode(bool antiAlias) { m_impl->antiAlias = antiAlias; SafeCall(m_impl->canvas, _antiAliasModeChanged(antiAlias)); }
EdgeSelector::EdgeSelector(const VectorView &vector) { SafeCall(igraph_es_vector_copy(ptr(), vector.ptr())); }
Matrix::Matrix(long int nrow, long int ncol) { SafeCall(igraph_matrix_init(ptr(), nrow, ncol)); }
int EdgeSelector::size(const Graph &graph) const noexcept { int result; SafeCall(igraph_es_size(graph.ptr(), ptr(), &result)); return result; }
Matrix &Matrix::operator/=(const Matrix &matrix) { SafeCall(igraph_matrix_div_elements(ptr(), matrix.ptr())); return *this; }
EdgeSelector EdgeSelector::Incident(int vid, Mode mode) { igraph_es_t es; SafeCall(igraph_es_incident(&es, vid, static_cast<igraph_neimode_t>(mode))); return EdgeSelector(es); }
Vector Matrix::colsums() const { Vector vector(nrow()); SafeCall(igraph_matrix_colsum(ptr(), vector.ptr())); return vector; }
EdgeSelector EdgeSelector::Pairs(const Vector &edge_vector, bool directed) { igraph_es_t es; SafeCall(igraph_es_pairs(&es, edge_vector.ptr(), directed)); return EdgeSelector(es); }
void Matrix::cbind(const Matrix &matrix) { SafeCall(igraph_matrix_cbind(ptr(), matrix.ptr())); }
void UpdateConsoleWidth( bool force ) { char buffer[128]; DWORD dw; LOGFONTA lf; TEXTMETRIC tm; RECT rc; int chars = 0; static int lastWidth = 0; static int lastChars = 0; if (!fn) return; if (!force && !autowidth) return; ::GetClientRect(hWndConsole, &rc); int width = rc.right - rc.left; if (width <= 0) return; if (!force && (lastWidth == width)) return; lastWidth = width; if (autowidth) { memset(&lf, 0, sizeof(LOGFONTA)); if (!CRegistryUtils::GetRegString(HKEY_CURRENT_USER, lf.lfFaceName, 32, REGISTRY_KEY, REGISTRY_VALUE_CONSOLE_FONT) || !strlen(buffer)) strcpy_s(lf.lfFaceName, 32, SCINTILLA_FONT_NAME); if (!CRegistryUtils::GetRegDWORD(HKEY_CURRENT_USER, &dw, REGISTRY_KEY, REGISTRY_VALUE_CONSOLE_SIZE) || dw <= 0) dw = SCINTILLA_FONT_SIZE; HDC dc = ::GetDC(0); lf.lfHeight = -MulDiv(dw, GetDeviceCaps(dc, LOGPIXELSY), 72); HFONT font = ::CreateFontIndirectA(&lf); HGDIOBJ oldFont = ::SelectObject(dc, font); ::GetTextMetrics(dc, &tm); DWORD pixels = MulDiv(tm.tmAveCharWidth, 72, GetDeviceCaps(dc, LOGPIXELSX)); ::SelectObject(dc, oldFont); ::DeleteObject(font); ::ReleaseDC(0, dc); // this should not work, as char width is in logical units. // 16 represents the scrollbar - too small? check chars = (rc.right - rc.left - 16) / (tm.tmAveCharWidth) - 1; } else { if (!CRegistryUtils::GetRegDWORD(HKEY_CURRENT_USER, &dw, REGISTRY_KEY, REGISTRY_VALUE_CONSOLE_WIDTH) || dw <= 0) dw = DEFAULT_CONSOLE_WIDTH; chars = dw; } if (chars < 10) chars = 10; if (chars > 1000) chars = 1000; if (chars == lastChars) return; lastChars = chars; SVECTOR sv; int r; sprintf_s(buffer, 128, "options(\"width\"=%d)", chars); sv.push_back(std::string(buffer)); SafeCall(SCC_EXEC, &sv, &r); DebugOut("%s\n", buffer); }