errorcode helper_fsm_start_peer_bday(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare local variables */ comm_msg_syn_flooded_t msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_3); /* do function */ /* receive message indicating that the flood happened */ CHECK_FAILED(readMsg(peer->info.socks.peer,COMM_MSG_SYN_FLOODED, &msg,sizeof(msg)),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received SYN_FLOODED\n"); /* set the value for the sequence number in the peer's info */ peer->info.bday.seq_num = msg.seq_num; peer->info.bday.seq_num_set = FLAG_SET; /* send message indicating the buddy is about to commence sending the * SYN/ACKs */ CHECK_FAILED(sendMsg(peer->info.socks.peer, COMM_MSG_BUDDY_SYN_ACK_FLOODED,NULL,0),ERROR_NETWORK_SEND); /* enter next state */ CHECK_FAILED(helper_fsm_end_peer_bday(list,peer,buddy), ERROR_CALLED_FUNCTION); return ERROR_1; }
errorcode helper_fsm_start_buddy_bday(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare local variables */ comm_msg_syn_ack_flood_seq_num_t msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_3); /* do function */ CHECK_FAILED(readMsg(peer->info.socks.peer, COMM_MSG_WAITING_TO_SYN_ACK_FLOOD,NULL,0),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received WAITING_TO_SYN_ACK_FLOOD\n"); /* as soon as the bday.seq_num_set flag is set, it is time for this * peer to flood synacks */ CHECK_FAILED(wait_for_buddy_syn_flood(&buddy->info),ERROR_1); /* make the message... */ msg.seq_num = buddy->info.bday.seq_num; /* ...and sent it */ CHECK_FAILED(sendMsg(peer->info.socks.peer, COMM_MSG_SYN_ACK_FLOOD_SEQ_NUM,&msg,sizeof(msg)), ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent SYN_ACK_FLOOD_SEQ_NUM\n"); /* enter the next state */ CHECK_FAILED(helper_fsm_end_buddy_bday(list,peer,buddy), ERROR_CALLED_FUNCTION); return ERROR_1; }
HRESULT CAnimationModel::SetupBoneMatrixPointers( LPD3DXFRAME pFrame ) { HRESULT hr = S_OK; LPD3DXMESHCONTAINER pMeshContainer = NULL; pMeshContainer = pFrame->pMeshContainer; while( NULL != pMeshContainer ) { hr = SetupBoneMatrixPointersOnMesh( pMeshContainer ); CHECK_FAILED( hr ); pMeshContainer = pMeshContainer->pNextMeshContainer; } if( NULL != pFrame->pFrameSibling ) { SetupBoneMatrixPointers( pFrame->pFrameSibling ); CHECK_FAILED( hr ); } if( NULL != pFrame->pFrameFirstChild ) { SetupBoneMatrixPointers( pFrame->pFrameFirstChild ); CHECK_FAILED( hr ); } return hr; }
HRESULT CAnimationModel::DrawFrame( LPD3DXFRAME pFrame ) { HRESULT hr = S_OK; LPD3DXMESHCONTAINER pMeshContainer = pFrame->pMeshContainer; while( NULL != pMeshContainer ) { hr = DrawMeshContainer( pFrame, pMeshContainer ); CHECK_FAILED( hr ); pMeshContainer = pMeshContainer->pNextMeshContainer; } if( pFrame->pFrameSibling ) { hr = DrawFrame( pFrame->pFrameSibling ); CHECK_FAILED( hr ); } if( pFrame->pFrameFirstChild ) { hr = DrawFrame( pFrame->pFrameFirstChild ); CHECK_FAILED( hr ); } return hr; }
errorcode helper_fsm_end_peer_bday(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare local variables */ comm_msg_bday_success_port_t receive_msg; comm_msg_buddy_port_t send_msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_3); /* do function */ if (FAILED(readMsg(peer->info.socks.peer,COMM_MSG_BDAY_SUCCESS_PORT, &receive_msg,sizeof(receive_msg)))) { peer->info.bday.status = FLAG_FAILED; return ERROR_NETWORK_READ; } /* set the port value */ peer->info.bday.port = receive_msg.port; peer->info.bday.port_set = FLAG_SET; peer->info.bday.status = FLAG_SUCCESS; /* this location for the external port is no longer valid, since the * flag was already set, but I set it here just in case I screwed up * somewhere else in the code and look at it */ peer->info.port_alloc.ext_port = receive_msg.port; peer->info.port_alloc.ext_port_set = FLAG_SET; /* send a message with the buddy's port, to go back to the buddy port * state. there is no need to wait for the port value to be set, it * is obviously set, since it was set before */ send_msg.ext_port = buddy->info.port_alloc.ext_port; send_msg.bday = COMM_BDAY_NOT_NEEDED; CHECK_FAILED(sendMsg(peer->info.socks.peer,COMM_MSG_BUDDY_PORT, &send_msg,sizeof(send_msg)),ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent BUDDY_PORT...again\n"); /* go to the start direct conncetion state now that all ports are * known */ CHECK_FAILED(helper_fsm_start_direct_conn(list,peer,buddy), ERROR_CALLED_FUNCTION); return SUCCESS; }
errorcode helper_fsm_hello(connlist_t *list, connlist_item_t *item) { /* declare variables */ comm_msg_hello_t hello; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(item,ERROR_NULL_ARG_2); /* do function */ /* this is a strange case, but it is OK if no acceptable message * is received on this read. It was probably a port prediction * second connection */ CHECK_FAILED(readMsg(item->info.socks.peer, COMM_MSG_HELLO, &hello, sizeof(hello)), ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received HELLO\n"); /* save out info from the message */ item->info.peer.port = hello.peer_port; item->info.peer.ip = hello.peer_ip; item->info.peer.set = FLAG_SET; item->info.buddy.int_ip = hello.buddy_int_ip; item->info.buddy.int_port = hello.buddy_int_port; item->info.buddy.ext_ip = hello.buddy_ext_ip; item->info.buddy.identifier = FLAG_SET; DEBUG(DBG_VERBOSE,"VERBOSE:Information from peer hello\n"); DEBUG(DBG_VERBOSE,"VERBOSE:peer.............%s:%u\n", DBG_IP(item->info.peer.ip), DBG_PORT(item->info.peer.port)); DEBUG(DBG_VERBOSE,"VERBOSE:buddy internal...%s:%u\n", DBG_IP(item->info.buddy.int_ip), DBG_PORT(item->info.buddy.int_port)); DEBUG(DBG_VERBOSE,"VERBOSE:buddy external...%s\n", DBG_IP(item->info.buddy.ext_ip)); /* send the next message */ CHECK_FAILED(sendMsg(item->info.socks.peer, COMM_MSG_CONNECT_AGAIN, NULL, 0),ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent CONNECT_AGAIN\n"); /* go to next state */ CHECK_FAILED(helper_fsm_conn2(list,item),ERROR_CALLED_FUNCTION); return SUCCESS; }
HRESULT CAnimationModel::DrawMeshContainer( LPD3DXFRAME pFrameBase, LPD3DXMESHCONTAINER pSuperMeshContainer ) { HRESULT hr = S_OK; if( NULL != pSuperMeshContainer->pSkinInfo ) { // 스키닝 방법에 따라 각각 다른 방법으로 렌더링 switch( SKINNING_TYPE ) { case NONINDEXED: hr = DrawMeshContainerByNonIndexed(pSuperMeshContainer); break; case INDEXED: hr = DrawMeshContainerByIndexed(pSuperMeshContainer); break; case VS: hr = DrawMeshContainerByVS(pSuperMeshContainer); break; case HLSL: hr = DrawMeshContainerByHLSL(pSuperMeshContainer); break; case SW: hr = DrawMeshContainerBySW(pSuperMeshContainer); break; } CHECK_FAILED( hr ); } else { CFrame *pFrame = (CFrame*) pFrameBase; CMeshContainer *pMeshContainer = (CMeshContainer*) pSuperMeshContainer; m_pd3dDevice->SetTransform( D3DTS_WORLD, &pFrame->m_CombinedTransformationMatrix ); for( DWORD i=0; i<pMeshContainer->NumMaterials; ++i ) { hr = m_pd3dDevice->SetMaterial( &pMeshContainer->m_pMaterials[i] ); CHECK_FAILED( hr ); hr = m_pd3dDevice->SetTexture( 0, pMeshContainer->m_ppTextures[i] ); CHECK_FAILED( hr ); hr = pMeshContainer->MeshData.pMesh->DrawSubset( i ); CHECK_FAILED( hr ); } } return hr; }
int main(int argc, char **argv) { int sock, ret; int connfd; int socklen; int childpid=0; struct sockaddr_in server_addr, client_addr; sock = socket(AF_INET, SOCK_STREAM, 0); CHECK_FAILED((-1 == sock), "socket error, "); TRACE("%d\n", sock); // memset(&addr, 0, sizeof(struct sockaddr_in)); bzero(&server_addr, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); server_addr.sin_port = htons(SERVER_PORT); ret = bind(sock, (const struct sockaddr*)&server_addr, sizeof(server_addr)); CHECK_FAILED((-1 == ret), "bind error, "); TRACE("(bind): %d\n", ret); ret = listen(sock, LISTENQ); CHECK_FAILED((-1 == ret), "listen error, "); TRACE("(listen): %d\n", ret); for(;;) { socklen = sizeof(client_addr); printf("[%d] wait request\n", getpid()); connfd = accept(sock, (struct sockaddr*)&client_addr, &socklen); CHECK_FAILED((-1 == connfd), "accept error, "); if((childpid = fork()) == 0 ) { printf("[%d] accept Request at %d.\n", getpid(), connfd); close(sock); do_echo(connfd); exit(0); } CHECK_FAILED((childpid < 0), "fork error, "); close(connfd); } return 0; }
HRESULT CAnimationModel::Render() { HRESULT hr = S_OK; hr = m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); CHECK_FAILED( hr ); hr = m_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL ); CHECK_FAILED( hr ); hr = m_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x10000000 ); CHECK_FAILED( hr ); hr = DrawFrame( m_pFrameRoot ); CHECK_FAILED( hr ); hr = m_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE ); CHECK_FAILED( hr ); return hr; }
void do_echo(int fd) { #define LEN 4096 static char buff[LEN]; int len; while(1) { len = read(fd, buff, LEN); buff[len] = '\0'; CHECK_FAILED((-1 == len), "read failed, "); printf("[%d] recv(%d) %s\n", getpid(), len, buff); if(len == 0) break; strcat(buff, "[ack]."); len = strlen(buff)+1; CHECK_FAILED((write(fd, buff, len) != len), "write faild, "); printf("[%d] send(%d) %s\n", getpid(), len, buff); } printf("[%d] session finished!.\n", getpid()); }
HRESULT CAnimationModel::InitDeviceObjects(LPDIRECT3DDEVICE9 pd3dDevice) { HRESULT hr = S_OK; if( NULL == pd3dDevice ) return E_INVALIDARG; m_pd3dDevice = pd3dDevice; m_pd3dDevice->AddRef(); // 커스텀 애니메신컨트롤러 를 생성 m_pAniController = new CAnimationController; // X파이을 읽어들여 애니메이션 가능한 모델을 만든다. if( NULL == m_pXFileName ) return E_FAIL; CAllocateHierarchy alloc; alloc.SetCreationFlag( TRUE ); alloc.SetDwFrame( 0 ); alloc.SetDwMeshContainer( 0 ); alloc.SetFrameVector( &vFrame ); alloc.SetMeshContainerVector( &vMeshContainer ); hr = D3DXLoadMeshHierarchyFromX( m_pXFileName , D3DXMESH_MANAGED , m_pd3dDevice , &alloc , NULL , &m_pFrameRoot , &m_pAniController->m_pAniController ); CHECK_FAILED( hr ); hr = SetupBoneMatrixPointers( m_pFrameRoot ); CHECK_FAILED( hr ); m_pAniController->InitDeviceObjects( m_pd3dDevice ); return hr; }
errorcode helper_fsm_start_direct_conn(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare local variables */ comm_msg_buddy_syn_seq_t buddy_syn_msg; comm_msg_peer_syn_seq_t peer_syn_msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_3); /* do function */ /* get message from peer with buddy seq num */ CHECK_FAILED(readMsg(peer->info.socks.peer,COMM_MSG_BUDDY_SYN_SEQ, &buddy_syn_msg,sizeof(buddy_syn_msg)),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received BUDDY_SYN_SEQ\n"); DEBUG(DBG_VERBOSE,"VERBOSE:sequence number is %u\n", DBG_SEQ_NUM(buddy_syn_msg.seq_num)); /* fill in the information about this syn sequence number */ peer->info.buddy_syn.seq_num = buddy_syn_msg.seq_num; peer->info.buddy_syn.seq_num_set = FLAG_SET; /* make payload to send in next message. first wait for the seq num * and then fill it in the payload */ CHECK_FAILED(wait_for_buddy_syn_seq_num(&(buddy->info)),ERROR_1); peer_syn_msg.seq_num = buddy->info.buddy_syn.seq_num; /* send the message */ CHECK_FAILED(sendMsg(peer->info.socks.peer,COMM_MSG_PEER_SYN_SEQ, &peer_syn_msg,sizeof(peer_syn_msg)),ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent PEER_SYN_SEQ\n"); /* enter next state */ CHECK_FAILED(helper_fsm_goodbye(list,peer,buddy), ERROR_CALLED_FUNCTION); return SUCCESS; }
errorcode helper_fsm_end_buddy_bday(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare local variables */ comm_msg_buddy_port_t msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_3); /* do function */ /* receive the message indicating the synack flood was done */ CHECK_FAILED(readMsg(peer->info.socks.peer,COMM_MSG_SYN_ACK_FLOOD_DONE, NULL,0),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received SYN_ACK_FLOOD_DONE\n"); /* wait for the buddy to set the external port */ CHECK_FAILED(wait_for_buddy_bday_port(&(buddy->info)),ERROR_1); /* now, resend the COMM_MSG_BUDDY_PORT message, but this time mark * the bday flag as unneeded */ msg.ext_port = buddy->info.bday.port; msg.bday = COMM_BDAY_NOT_NEEDED; /* now send the message */ CHECK_FAILED(sendMsg(peer->info.socks.peer,COMM_MSG_BUDDY_PORT, &msg,sizeof(msg)),ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent BUDDY_PORT...again\n"); /* go to the start direct conncetion state now that all ports are * known */ CHECK_FAILED(helper_fsm_start_direct_conn(list,peer,buddy), ERROR_CALLED_FUNCTION); return SUCCESS; }
errorcode helper_fsm_goodbye(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare local variables */ comm_msg_goodbye_t goodbye; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_2); /* do function */ /* receive the message */ CHECK_FAILED(readMsg(peer->info.socks.peer,COMM_MSG_GOODBYE, &goodbye, sizeof(goodbye)),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received GOODBYE\n"); DEBUG(DBG_VERBOSE,"VERBOSE:peer's connection was %sa success!\n", ((goodbye.success_or_failure==FLAG_FAILED) ? "not ": "")); return SUCCESS; }
int p2p_helper(void) { int sockfd; // Sockfd int i; // Tmp conn_list list; // Connection List conn_list_item item; // struct sockaddr_in addr;// save addr struct p2pinfo info; // if ((sockfd = Network_init(2342)) < 0) // Init Network return ERROR_NETWORK_INIT; // Return Error CHECK_FAILED(conn_list_init(&(list)),ERROR_LIST_INIT); // Init List while(1) { bzero((void *)&addr,addr_size); recvfrom(sockfd,(void *)&(item.info.Dest.sin_addr.s_addr),ip_size,0,(struct sockaddr *)&addr,&len); // Recv Dest IP item.info.Src=addr; // Save Src Addr printf("DestIP=%s\n",inet_ntoa(item.info.Dest.sin_addr)); // Debug printf("SrcIP\t=%s\nSrcPort\t=%d\n",inet_ntoa(item.info.Src.sin_addr),addr.sin_port); // Debug i = conn_list_find(&list,item.info,&(item.info.Dest)); // Search for This IP if (i == -14) // If Not Found { conn_list_add(&list,item); // Add item continue; } info.Dest = item.info.Dest; info.is_server = 1; sendto(sockfd,(void *)&info,info_size,0,(struct sockaddr *)&(item.info.Src),len); info.Dest = item.info.Src; info.is_server = 0; sendto(sockfd,(void *)&info,info_size,0,(struct sockaddr *)&(item.info.Dest),len); conn_list_remove(&list,&item); // remove item } exit(0); }
errorcode helper_fsm_conn2(connlist_t *list, connlist_item_t *item) { /* declare local variables */ observed_data_t find_data; connlist_item_t *port_pred_item = NULL; comm_msg_pred_port_t msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(item,ERROR_NULL_ARG_2); /* do function */ CHECK_FAILED(readMsg(item->info.socks.peer, COMM_MSG_CONNECTED_AGAIN, NULL,0),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:CONNECTED_AGAIN\n"); /* look for info about this second connection in the list */ /* copy of the observed data */ memcpy(&find_data, &item->obs_data, sizeof(observed_data_t)); /* and expect the port prediction port to be on the next sequential * port */ find_data.port = PORT_ADD(find_data.port,1); /* wait 2 seconds, to give the second connection time to add * it's item to the list (this is instead of having a timeout, in * essence always wait the full timeout) */ DEBUG((DBG_PORT_PRED|DBG_LIST), "PORT_PRED|LIST:finding 2nd connection entry in list\n"); if (FAILED(find_conn2(list,&find_data,&port_pred_item))) { DEBUG(DBG_PORT_PRED,"PORT_PRED:couldn't find 2nd connection\n"); msg.port_alloc = COMM_PORT_ALLOC_RAND; /* set the allocation method */ item->info.port_alloc.method = COMM_PORT_ALLOC_RAND; item->info.port_alloc.method_set = FLAG_SET; /* set the external port definitively to unknown */ item->info.port_alloc.ext_port = PORT_UNKNOWN; item->info.port_alloc.ext_port_set = FLAG_SET; } else { DEBUG(DBG_PORT_PRED,"PORT_PRED:found 2nd connection\n"); msg.port_alloc = COMM_PORT_ALLOC_SEQ; /* set the port allocation method */ item->info.port_alloc.method = COMM_PORT_ALLOC_SEQ; item->info.port_alloc.method_set = FLAG_SET; /* set the predicted port to 2 higher than the port for this * connection */ item->info.port_alloc.ext_port = PORT_ADD( item->obs_data.port,2); item->info.port_alloc.ext_port_set = FLAG_SET; /* forget about the port prediction second connection */ DEBUG(DBG_LIST, "LIST:forgeting about port pred entry\n"); CHECK_FAILED(connlist_forget(list,connlist_item_match, port_pred_item),ERROR_1); } DEBUG(DBG_PORT_PRED, "PORT_PRED:port alloc method is %s\n", (item->info.port_alloc.method==COMM_PORT_ALLOC_SEQ) ? "sequential" : "random" ); /* tell the peer the port allocation method */ CHECK_FAILED(sendMsg(item->info.socks.peer, COMM_MSG_PORT_PRED, &msg,sizeof(msg)),ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent PORT PRED\n"); /* enter next state */ CHECK_FAILED(helper_fsm_buddy_alloc(list,item),ERROR_CALLED_FUNCTION); return SUCCESS; }
int main(int argc, char** argv) { int rc=0, fail = 0; #ifdef HAVE_EPETRAEXT bool verbose = false; int localProc = 0; // std::string *fstr; #ifdef HAVE_MPI int numProcs; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &localProc); MPI_Comm_size(MPI_COMM_WORLD, &numProcs); const Epetra_MpiComm Comm(MPI_COMM_WORLD); #else const Epetra_SerialComm Comm; #endif Teuchos::CommandLineProcessor clp(false,true); // --f=fileName provides a different matrix market file for input // --v will print out the partitioning (small files only) std::string *inputFile = new std::string("simple.mtx"); bool runAll = false; clp.setOption( "f", inputFile, "Name of input matrix market file"); clp.setOption( "run-all", "abort", &runAll, "Don't abort if one test fails, run all of them."); clp.setOption( "v", "q", &verbose, "Display matrix before and after partitioning."); Teuchos::CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv); if( parse_return == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED){ #ifdef HAVE_MPI MPI_Finalize(); #endif return 0; } if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) { #ifdef HAVE_MPI MPI_Finalize(); #endif return 1; } const char *fname = inputFile->c_str(); // Read in the matrix market file and distribute its rows across the // processes. // // This reader uses the default Epetra_Map for number of rows for the // RowMap() and for the RangeMap(). For non-square matrices it uses // the default Epetra_Map for the number of columns for the DomainMap(), // otherwise it uses the RowMap(). // // The maps can be specified with other versions of MMFtoCrsMatrix(). Epetra_CrsMatrix *matrixPtr; rc = EpetraExt::MatrixMarketFileToCrsMatrix(fname, Comm, matrixPtr); if (rc < 0){ if (localProc==0){ std::cout << "error reading input file" << std::endl << "FAIL" << std::endl; } exit(1); } bool square = (matrixPtr->NumGlobalRows() == matrixPtr->NumGlobalCols()); // If matrix is square, determine if it's symmetric TODO // Run some partitioning tests // Test graph and hypergraph partitioning // Test with and without application supplied weights // Test the Epetra_CrsMatrix interface and also the Epetra_CrsGraph interface // Do tests where the vertex or edge weights vary widely Teuchos::RCP<Epetra_CrsMatrix> testm = Teuchos::rcp(matrixPtr); int failures = 0; #ifdef SHORT_TEST fail = run_test(testm, verbose, false, // do not test #partitions < #processes NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_CRSGRAPH); CHECK_FAILED(); goto Report; #else if (square){ #ifdef HAVE_ISORROPIA_ZOLTAN fail = run_test(testm, // test matrix verbose, // display matrix before and after? false, // do not test #partitions < #processes GRAPH_PARTITIONING, // perform zoltan graph partitioning NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_LINEARPROBLEM); // use linear problem interface of isorropia CHECK_FAILED(); fail = run_test(testm, verbose, // draw graph before and after partitioning? false, // do not test #partitions < #processes HYPERGRAPH_PARTITIONING, // do graph partitioning NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_CRSMATRIX); // use the Epetra_CrsMatrix interface CHECK_FAILED(); fail = run_test(testm, verbose, true, // test #partitions < #processes GRAPH_PARTITIONING, NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_CRSMATRIX); CHECK_FAILED(); fail = run_test(testm, verbose, false, // do not test #partitions < #processes GRAPH_PARTITIONING, NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_LINEARPROBLEM); CHECK_FAILED(); fail = run_test(testm, verbose, false, // do not test #partitions < #processes GRAPH_PARTITIONING, NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_ROWMATRIX); CHECK_FAILED(); #else fail = 0; if (localProc == 0){ std::cout << "Test not run because it requires EPETRA_EXT" << std::endl; } #endif #ifdef HAVE_ISORROPIA_ZOLTAN fail = run_test(testm, verbose, true, // test #partitions < #processes HYPERGRAPH_PARTITIONING, NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_CRSGRAPH); CHECK_FAILED(); fail = run_test(testm, verbose, false, // do not test #partitions < #processes HYPERGRAPH_PARTITIONING, NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_ROWMATRIX); CHECK_FAILED(); fail = run_test(testm, verbose, false, // do not test #partitions < #processes HYPERGRAPH_PARTITIONING, NO_APPLICATION_SUPPLIED_WEIGHTS, NO_APPLICATION_SUPPLIED_WEIGHTS, EPETRA_LINEARPROBLEM); CHECK_FAILED(); #endif } #endif // SHORT_TEST #else fail = 0; if (localProc == 0){ std::cout << "Test not run because it requires EPETRA_EXT" << std::endl; } #endif Report: #ifdef HAVE_MPI MPI_Finalize(); #endif if (localProc == 0){ if (failures){ if (failures > 1) std::cout << std::endl << failures << " FAILURES" << std::endl; else std::cout << std::endl << "1 FAILURE" << std::endl; if (!runAll){ std::cout << "(Use option --run-all if you do not want this test to abort on failure)" << std::endl; } } else std::cout << std::endl << "PASS" << std::endl; } return fail; }
int natblaster_connect(ip_t helper_ip, port_t helper_port, ip_t peer_ip, port_t peer_port, ip_t buddy_ext_ip, ip_t buddy_int_ip, port_t buddy_int_port, char *device, flag_t random) { peer_conn_info_t info; /* the return type is "int", but I return "errorcode"s because I know that * they are the same real type and that all the errorcodes are negative. * This makes debugging easier. */ /* first find a device if needed */ if (device==NULL) CHECK_FAILED(findDevice(&device),ERROR_NO_DEV_FOUND); DEBUG(DBG_VERBOSE, "VERBOSE:connecting to Buddy....%s:%uint\n", DBG_IP(buddy_int_ip), DBG_PORT(buddy_int_port)); DEBUG(DBG_VERBOSE," %sext\n", DBG_IP(buddy_ext_ip)); DEBUG(DBG_VERBOSE, "VERBOSE:from local address.....%s:%u\n", DBG_IP(peer_ip), DBG_PORT(peer_port)); DEBUG(DBG_VERBOSE, "VERBOSE:with helper............%s:%u\n", DBG_IP(helper_ip), DBG_PORT(helper_port)); DEBUG(DBG_VERBOSE, "VERBOSE:using Device...........%s\n", device); DEBUG(DBG_VERBOSE, "VERBOSE: this peer is %srandom\n", (random==FLAG_SET ? "" : "not ")); /* now put the info in a conn_info structure */ info.helper.ip = helper_ip; info.helper.port = helper_port; info.peer.ip = peer_ip; info.peer.port = peer_port; info.peer.set = FLAG_SET; info.buddy.int_ip = buddy_int_ip; info.buddy.int_port = buddy_int_port; info.buddy.ext_ip = buddy_ext_ip; info.buddy.identifier = FLAG_SET; info.buddy.ext_port = PORT_UNKNOWN; info.buddy.ext_port_set = FLAG_UNSET; info.socks.helper = SOCKET_UNKNOWN; info.socks.helper_pred = SOCKET_UNKNOWN; info.socks.buddy = SOCKET_UNKNOWN; info.device = device; info.direct_conn_status = FLAG_UNSET; info.bday.stop_synack_find = FLAG_UNSET; /* buddy sock gets filled in below */ /* bind the desired port for a connection to buddy */ CHECK_FAILED(bindSocket(info.peer.port,&info.socks.buddy),ERROR_1); /* bind socket for helper connection (2 before buddy port); */ if (random==FLAG_UNSET) info.helper_conn.persistent_port = PORT_ADD(peer_port,-2); else /* bind a "random" port (not the conventional port) */ info.helper_conn.persistent_port = PORT_ADD(peer_port,-3); CHECK_FAILED(bindSocket(info.helper_conn.persistent_port, &info.socks.helper),ERROR_2); /* bind port for second helper connection */ info.helper_conn.prediction_port = PORT_ADD(peer_port,-1); CHECK_FAILED(bindSocket(info.helper_conn.prediction_port, &info.socks.helper_pred),ERROR_3); if (FAILED(peer_fsm_start(&info))) { /* close the sockets */ close(info.socks.helper); close(info.socks.helper_pred); close(info.socks.buddy); return ERROR_4; } /* close helper sockets */ close(info.socks.helper); close(info.socks.helper_pred); return info.socks.buddy; }
errorcode helper_fsm_buddy_alloc(connlist_t *list, connlist_item_t *item) { /* declare variables */ connlist_item_t *found_buddy = NULL; comm_msg_buddy_alloc_t msg; errorcode ret; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(item,ERROR_NULL_ARG_2); /* do function */ ret = SUCCESS; /* receive the waiting message */ CHECK_FAILED(readMsg(item->info.socks.peer, COMM_MSG_WAITING_FOR_BUDDY_ALLOC,NULL,0),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received WAITING_FOR_BUDDY_ALLOC\n"); /* get pointer to buddy's info*/ if (FAILED(get_buddy(list,item,&found_buddy))){ DEBUG(DBG_BUDDY,"BUDDY:couldn't find buddy\n"); return ERROR_1; } DEBUG(DBG_BUDDY,"BUDDY:found buddy\n"); /* check to make sure all buddy's info has been filled in, * then fill in the message */ if (FAILED(wait_for_buddy_port_alloc(&(found_buddy->info)))){ ret = ERROR_1; goto forget_and_return; } msg.buddy_port_alloc = found_buddy->info.port_alloc.method; if ( (found_buddy->info.port_alloc.method == COMM_PORT_ALLOC_RAND) && (item->info.port_alloc.method == COMM_PORT_ALLOC_RAND) ) msg.support = COMM_CONNECTION_UNSUPPORTED; else msg.support = COMM_CONNECTION_SUPPORTED; /* send out message*/ if (FAILED(sendMsg(item->info.socks.peer,COMM_MSG_BUDDY_ALLOC, &msg,sizeof(comm_msg_buddy_alloc_t)))) { ret = ERROR_NETWORK_SEND; DEBUG(DBG_PROTOCOL, "fsm_buddy_alloc:PROTOCOL:sent BUDDY_ALLOC\n"); goto forget_and_return; } if (msg.support == COMM_CONNECTION_UNSUPPORTED) { DEBUG(DBG_VERBOSE, "VERBOSE:connection unsupported!\n"); ret = ERROR_2; goto forget_and_return; } /* enter next state */ if (FAILED(helper_fsm_buddy_port(list,item,found_buddy))) { ret = ERROR_CALLED_FUNCTION; goto forget_and_return; } forget_and_return: /* forget the buddy's info */ DEBUG(DBG_LIST, "LIST:forgeting about buddy entry\n"); CHECK_FAILED(connlist_forget(list,connlist_item_match,found_buddy), ERROR_3); return ret; }
errorcode helper_fsm_buddy_port(connlist_t *list, connlist_item_t *peer, connlist_item_t *buddy) { /* declare variables */ comm_msg_buddy_port_t msg; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(peer,ERROR_NULL_ARG_2); CHECK_NOT_NULL(buddy,ERROR_NULL_ARG_3); /* do function */ /* get message from peer */ CHECK_FAILED(readMsg(peer->info.socks.peer, COMM_MSG_WAITING_FOR_BUDDY_PORT,NULL,0),ERROR_NETWORK_READ); DEBUG(DBG_PROTOCOL,"PROTOCOL:received WAITING_FOR_BUDDY_PORT\n"); /* as soon as the buddy's port is known send it to the peer and attach * a note indicating if the peer should do the birthday paradox so it's * port can be detected (the peer should be able to determine on it's * own if this is needed because the helper already told the peer the * peer's port allocation method, so this is for sanity checking only) */ /* wait for the buddy's port */ CHECK_FAILED(wait_for_buddy_port_known(&(buddy->info)),ERROR_1); /* fill in the message */ msg.ext_port = buddy->info.port_alloc.ext_port; msg.bday = ( ( (peer->info.port_alloc.method == COMM_PORT_ALLOC_RAND) || (buddy->info.port_alloc.method == COMM_PORT_ALLOC_RAND)) ? COMM_BDAY_NEEDED : COMM_BDAY_NOT_NEEDED ); /* send the message */ CHECK_FAILED(sendMsg(peer->info.socks.peer,COMM_MSG_BUDDY_PORT, &msg,sizeof(msg)),ERROR_NETWORK_SEND); DEBUG(DBG_PROTOCOL,"PROTOCOL:sent BUDDY_PORT\n"); /* enter next state - it depends on port allocation method */ if (peer->info.port_alloc.method==COMM_PORT_ALLOC_RAND) { /* this connections peer is random */ CHECK_FAILED(helper_fsm_start_peer_bday(list,peer,buddy), ERROR_CALLED_FUNCTION_1); } else if (buddy->info.port_alloc.method==COMM_PORT_ALLOC_RAND) { /* the buddy connection is random, the peer is going to * need to help find a port */ CHECK_FAILED(helper_fsm_start_buddy_bday(list,peer,buddy), ERROR_CALLED_FUNCTION_2); } else { /* neither peer is random, go ahead with connection */ CHECK_FAILED(helper_fsm_start_direct_conn(list,peer,buddy), ERROR_CALLED_FUNCTION_3); } /** * there is no check to make sure both peers aren't random, it is assumed * that this case is handled in an earlier state (since it is * unsupported). **/ return SUCCESS; }
errorcode helper_fsm_start(connlist_t *list, connlist_item_t *item) { /* declare variables */ errorcode ret; /* error check arguments */ CHECK_NOT_NULL(list,ERROR_NULL_ARG_1); CHECK_NOT_NULL(item,ERROR_NULL_ARG_2); /* do function */ /* set initial values */ item->info.port_alloc.method = COMM_PORT_ALLOC_UNKNOWN; item->info.port_alloc.method_set = FLAG_UNSET; item->info.port_alloc.ext_port = PORT_UNKNOWN; item->info.port_alloc.ext_port_set = FLAG_UNSET; item->info.peer.ip = IP_UNKNOWN; item->info.peer.port = PORT_UNKNOWN; item->info.peer.set = FLAG_UNSET; item->info.buddy.ext_ip = IP_UNKNOWN; item->info.buddy.ext_port = PORT_UNKNOWN; item->info.buddy.int_ip = IP_UNKNOWN; item->info.buddy.int_port = PORT_UNKNOWN; item->info.buddy.identifier = FLAG_UNSET; item->info.buddy.ext_port_set = FLAG_UNSET; item->info.buddy_syn.seq_num = SEQ_NUM_UNKNOWN; item->info.buddy_syn.seq_num_set = FLAG_UNSET; item->info.bday.seq_num = SEQ_NUM_UNKNOWN; item->info.bday.seq_num_set = FLAG_UNSET; item->info.bday.port = PORT_UNKNOWN; item->info.bday.port_set = FLAG_UNSET; item->info.bday.status = FLAG_UNSET; /* add info to the list */ if(FAILED(connlist_add(list,item))) { /* close the socket */ close(item->info.socks.peer); return ERROR_LIST_ADD; } DEBUG(DBG_LIST,"LIST:item Watchers: %d\n",(int)item->watchers); /* call next state */ ret = helper_fsm_hello(list,item); if (FAILED(ret)) { if (ret==ERROR_NETWORK_READ){ DEBUG(DBG_PROTOCOL,"PROTOCOL:no hello message\n"); } /* close the socket */ close(item->info.socks.peer); /* if the state fails, remove the list item */ CHECK_FAILED(connlist_forget(list,connlist_item_match,item), ERROR_LIST_REMOVE_1); return ERROR_CALLED_FUNCTION; } /* close the socket */ close(item->info.socks.peer); CHECK_FAILED(connlist_forget(list,connlist_item_match,item), ERROR_LIST_REMOVE_2); return SUCCESS; }