1 / 14

Lab1

Lab1. TA: Yi Cui 01/22/2013. Parallel graph search. Communication between processes Graph search technics BFS DFS bFS A* Multiple threads. Part 1. Goals Learn to use Windows API CreateFile ReadFile WriteFile … Learn to communicate between processes using a pipe Create a pipe

gyala
Télécharger la présentation

Lab1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab1 TA: Yi Cui 01/22/2013

  2. Parallel graph search • Communication between processes • Graph search technics • BFS • DFS • bFS • A* • Multiple threads

  3. Part 1 • Goals • Learn to use Windows API • CreateFile • ReadFile • WriteFile • … • Learn to communicate between processes using a pipe • Create a pipe • Send/receive message through a pipe • Terminate your program clearly

  4. Part 1 Your process CC process Start CC process (CreateProcess) Build a pipe to CC (CreateFile) Send parameters to CC (WriteFile) Read response from CC (ReadFile) Build a pipe to robot (CreateFile) Connect to robot (WriteFile) Read response from robot (ReadFile) Print out initial room id Generate graph, create robots, send response back Send robot response back, including initial room id

  5. Part 1 • Two steps for clear termination • Cloese robots • Send DISCONNECT message to each robot (WriteFile) • Wait for robots to terminate (WaitForSingleObject) (optional) • CloeseHandle • Close CC • Send DISCONNECT message to CC (WriteFile) • Wait for CC to terminate (WaitForSingleObject) (must) • CloseHandle

  6. Part 1 • Read pipe message • Difficulty: size is unknown in ahead of time • Correct way: • Try to read BUF_SIZE bytes • If (bytesRead == BUF_SIZE) // possibly more bytes • { • Use PeekNamedPipe to check how many bytes left, say x bytes • Re-allocate a new buffer with size BUF_SIZE + x • Copy data from old buffer to new buffer • Read rest x bytes • } • Why not do PeekNamedPipe first? Check x != 0 Delete old buffer

  7. C Pointers • strcpy(char* str1, char* str2) • copy str2 to str1 • For example, copy “abcdefgh” to a string char* ptr; strcpy(ptr, “abcdefgh”); char* ptr= new char[5]; strcpy(ptr, “abcdefgh”); char* ptr = new char[8]; strcpy(ptr, “abcdefgh”); char* ptr = new char[9]; strcpy(ptr, “abcdefgh”); char* ptr; ptr = “abcdefgh”; ptr[1] = ‘x’; (crash, static array, read only)

  8. C Pointers • strcat(char* str1, char* str2) • append str2 to the end of str1 • For example, append “def” to “abc” char* ptr = new char[6]; strcpy(ptr, “abc”); strcat(ptr, “def”); char* ptr = new char[7]; strcpy(ptr, “abc”); strcat(ptr, “def”);

  9. C Pointers • memcpy(char* str1, char* str2, int n) • copy n bytes from str2 to str1 • For example char* ptr = new char[4]; memcpy(ptr, “abcd”, 4); intlen = strlen(ptr); Incorrect!

  10. C Pointer • Practice • Dynamic buffer class MyBuf { public: char* buf; intdataSize; intbufSize; void ReSize(intnewSize); }; MyBuf *mb = new MyBuf; mb->buf = new char[5]; mb->dataSize = 0; mb->bufSize = 5; memcpy(mb->buf, “abc”, 3); mb->dataSize = 3; void MyBuf::ReSize(intnewSize) {}

  11. C Pointers class NodeTuple64 { public: uint64 node; float intensity; }; sizeof(NodeTuple64) ?

  12. C Pointers char* ptr = new char[20]; NodeTuple64* tuple = (NodeTuple64*)ptr; tuple->node = 1; tuple->intensity = 0.5; ptr++; tuple++; sizeof(NodeTuple64) vs. sizeof(tuple) ptr ptr 1 0.5 tuple tuple

  13. Windows API • Practice • Open Notepad, type 10 characters “abcdefghij”, save it • Use CreateFile & ReadFile to read 10 bytes from that file and display it on screen

  14. Q&A

More Related