Exemplo n.º 1
0
void distributed_control::close_all_connections() {
  mpi_barrier();
  logger(LOG_INFO, "Closing sockets");
  done = 1;
  mpi_barrier();
  // wake all receivers up everyone up;
  for (procid_t j = 0 ;j < numprocs(); ++j) {
    if (j != procid()) {
      char *a = (char*)malloc(16);
      memset(a, 0, 16);
      send_to_sock(j, a, 1);
    }
  }
  procthreads.join();
  mpi_barrier();
  // socket closing order.to avoid TIME_WAITs
  // close initiators first
  for (procid_t j = procid()+1;j < numprocs(); ++j) {
    close(socks[j]);
  }
  mpi_barrier();
  // then close everything else
  for (procid_t j = 0 ;j < procid(); ++j) {
    close(socks[j]);
  }
  close(listensock);
  // wake up all threads
  procthreads.signalall(SIGURG);
  logger(LOG_INFO, "All sockets closed");
}
Exemplo n.º 2
0
void distributed_control::connect_udt() {
  open_listening_udt();
  socks.resize(numprocs());
  socks[procid()] = 0;
  mpi_barrier();
  // this is a little tricky. both connect() and accept() blocks.
  // so I have to do this in phases
  for (procid_t i = 0;i < numprocs(); ++i) {
    if (procid() == i) {
      // my turn to connect to everyone. I only need to connect to those with
      // id above me
      for (procid_t j = i+1;j < numprocs(); ++j) {
      
        sockfd_t newsock = socket(AF_INET, SOCK_STREAM, 0);
        sockaddr_in serv_addr;
        serv_addr.sin_family = AF_INET;
        // set the target port
        serv_addr.sin_port = htons(DC_LOCAL_BASE_PORT_NUM + j);
        // set the target address
        serv_addr.sin_addr = *(struct in_addr*)&(all_addrs[j]);
        memset(&(serv_addr.sin_zero), '\0', 8);
        // Connect!
        logstream(LOG_INFO) << "Trying to connect from "
                            << i << " -> " << j
                            << " on port " << DC_LOCAL_BASE_PORT_NUM + j << "\n";
        logger(LOG_INFO, "Destination IP = %s", inet_ntoa(serv_addr.sin_addr));
        if (connect(newsock, (sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) {
          logstream(LOG_FATAL) << "connect " << i << " to " << j << ": "
                               << strerror(errno) << "\n";
          ASSERT_TRUE(false);
        }
        logstream(LOG_INFO) << "Sent connection " << i << " -> " << j << "\n";
        // store in the socks table
        set_socket_options(newsock);
        socks[j] = newsock;

      }
    }
    else if (procid() > i) {
      logstream(LOG_INFO) << "Proc " << procid() << " Waiting to accept\n";
      
      sockaddr_in their_addr;
      socklen_t namelen = sizeof(sockaddr_in);
      // this is a socket to i
      socks[i] = accept(listensock, (sockaddr*)&their_addr, &namelen);
      set_socket_options(socks[i]);
      logstream(LOG_INFO) << "Accepted connection " << i << " -> " << procid() << "\n";
    }
    mpi_barrier();
  }
  // allocate the locks
  sendlocks.resize(socks.size());
  recvlocks.resize(socks.size());
  logstream(LOG_INFO) << "All connections constructed\n";
}
Exemplo n.º 3
0
void display()
{
    int	image = 0;

    tty_printf(" !!!  Processor %d running !!!\n", procid());

    while(image < NIMAGES)
    {
        while( buf_out_empty == TRUE ) {} // synchro

        tty_printf("\n *** starting display for image %d at cycle %d\n", image, proctime());
        if ( fb_write(0, buf_out, NLINES*NPIXELS) )
        {
                tty_printf("echec fb_sync_write\n");
                exit();
        }
        else
        {
            tty_printf("*** success fb_write ***\n");
        }

        if ( fb_completed() )
        {
            tty_printf("echec fb_completed\n");
            exit();
        }

        buf_out_empty = TRUE;

        tty_printf(" *** completing display for image %d at cycle %d\n", image, proctime());
        image++;
    } // end while image
    exit();
} // end display
Exemplo n.º 4
0
void transpose()
{
    int l,p;
    int image = 0;

    tty_printf(" !!!  Processor %d running !!!\n", procid());

    while( image < NIMAGES )
    { 
        while( (buf_in_empty == TRUE) || (buf_out_empty == FALSE) ) {}	// synchro

        tty_printf("\n *** Starting transpose for image %d *** at cycle %d \n", image, proctime());
        for( l=0 ; l<NLINES ; l++)
        {
            for( p=0 ; p<NPIXELS ; p++)
            {
                    buf_out[l][p] = buf_in[p][l];
            } 
        }

        buf_in_empty = TRUE;
        buf_out_empty = FALSE;

        tty_printf(" *** Completing transpose for image %d *** at cycle %d \n", image, proctime());
        image++;
    } // end while image
    exit();
} // end transpose
Exemplo n.º 5
0
void load()
{
    int image = 0;

    tty_printf(" !!!  Processor %d running !!!\n", procid());

    while(image < NIMAGES) 
    {
        while ( buf_in_empty == FALSE ) {}	// synchro
        
        tty_printf("\n *** Starting load for image %d *** at cycle %d \n", image, proctime());
        if( ioc_read(image*NBLOCKS, buf_in, NBLOCKS) )
        {
            tty_printf("echec ioc_read \n");
            exit();
        }
        if ( ioc_completed() )
        {
            tty_printf("echec ioc_completed\n");
            exit();
        }

        buf_in_empty = FALSE;

        tty_printf(" *** Completing load for image %d *** at cycle %d \n", image, proctime());
        image++;
    } // end while image      
    exit();
} // end load()
Exemplo n.º 6
0
void distributed_control::comms_barrier() {
  logger(LOG_INFO, "%d comms barrier", procid());
  logstream(LOG_INFO) << msgsent.value << " " << msgprocessed.value << std::endl;
  terminator->reset();
  mpi_barrier();
  while (!terminator->done(msgsent.value, msgprocessed.value)) {
    sched_yield();
  }
  terminator->reset();
}
Exemplo n.º 7
0
void distributed_control::open_listening_udt() {
  // open listening socket
  listensock = socket(AF_INET, SOCK_STREAM, 0);
  sockaddr_in my_addr;
  my_addr.sin_family = AF_INET;
  my_addr.sin_port = htons(localport);
  my_addr.sin_addr.s_addr = INADDR_ANY;
  memset(&(my_addr.sin_zero), '\0', 8);
  logstream(LOG_INFO) << "Proc " << procid() << " Bind on " << localport << "\n";
  if (bind(listensock, (sockaddr*)&my_addr, sizeof(my_addr)) < 0)
  {
    logstream(LOG_FATAL) << "bind: " << strerror(errno) << "\n";
    ASSERT_TRUE(0);
  }
  logstream(LOG_INFO) << "Proc " << procid() << " listening on " << localport << "\n";
  if (numprocs() > 1) {
    ASSERT_EQ(0, listen(listensock, numprocs() - 1));
  }
}
Exemplo n.º 8
0
void printAudioInfo(){
	int sessionCount = getSessionID();
	printf("\n\n\n\n\n\n\n\n");
	printf("################################################################################");
	printf("     Audio Sessions \n");
	printf("################################################################################");
	printf("[id] PID  - %-10s - %-50s\n","process","Main-Window Title");
	printf("--------------------------------------------------------------------------------");
	for (int sessionID(0); sessionID < sessionCount; sessionID++){
		CComPtr<IAudioSessionControl> pSessionControl;
		CComPtr<ISimpleAudioVolume> pSAV;
		CComPtr<IAudioSessionControl2> pSC2;
		// Get SessionControl
		if (FAILED(pAudioSessionEnumerator->GetSession(sessionID, &pSessionControl)))
			continue;
		// Ask for SimpleAudioVolume
		if (FAILED(pSessionControl->QueryInterface(__uuidof(ISimpleAudioVolume), (VOID**)&pSAV)))
			continue;
		// audio session 2 for extended name info
		if (FAILED(pSessionControl->QueryInterface(__uuidof(IAudioSessionControl2), (VOID**)&pSC2)))
			continue;
		LPWSTR name1,name2,icon;
		DWORD procid(0);
		float vol = 0;
		
		pSessionControl->GetDisplayName(&name1);
		pSessionControl->GetIconPath(&icon);
		pSC2->GetSessionIdentifier(&name2);
		pSC2->GetProcessId(&procid);
		
		procid = getSessionPID(sessionID);
		getPIDName(procid);
		getPIDTitle(procid);

		pSAV->GetMasterVolume(&vol);
//		printf("Session[%d] Vol[%.2f]\nDisplayName: %ls\nSessionIdentifier: %ls\nProcessId: %d\nMainWindowTitle: %s\nProcessName: %s\nIconPath: %s\n\n", i, vol, name1, name2, procid, title, procname, icon);
//		printf("Session[%d] Vol[%.2f]\nDisplayName: %ls\nProcessId: %d\nMainWindowTitle: %s\nProcessName: %s\nIconPath: %s\n\n", i, vol, name1, procid, title, procname, icon);

		//18+name+laststring
		printf("[% 2d]% 5d - %-10.10s - %-50.50s\n", sessionID, procid, g_pidName, g_pidTitle);

		CoTaskMemFree(name1); // TODO: to be done better :/
		CoTaskMemFree(name2);
		CoTaskMemFree(icon);
	}
	printf("--------------------------------------------------------------------------------");
}
Exemplo n.º 9
0
void distributed_control::sync_ip_list() {
  // get the local IP
  char localip[4];
  get_local_ip(localip);
  struct in_addr* localipinaddr = (struct in_addr*)(localip);
  logger(LOG_INFO, "Local IP = %s", inet_ntoa(*localipinaddr));

  // build the gather op for all addresses
  all_addrs = new uint32_t[numprocs()];

  MPI_Allgather(localip, 4,  MPI_CHAR,
                all_addrs , 4, MPI_CHAR, MPI_COMM_WORLD);
  
  for (procid_t i = 0;i < numprocs(); ++i) {
    logger(LOG_INFO, "Node %d IP = %s",i, inet_ntoa(*(struct in_addr*)&(all_addrs[i])));
  }
  localport = DC_LOCAL_BASE_PORT_NUM + procid();
}