예제 #1
0
int main()
{
    int *arr;
    int count = 0;
    unsigned int size = 5000*5000;
   struct timeval ptimes,ptimee,ptimed,stimes,stimee,stimed;   
    arr = (int*) malloc (sizeof(int) * size);

    initMat(arr,size);
    gettimeofday(&stimes, NULL);
        scount(arr,size,&count);
    gettimeofday(&stimee, NULL);

    printf("Count : %d\n",count);
    count = 0;

    gettimeofday(&ptimes, NULL);
        count = pcount(arr,size);
    gettimeofday(&ptimee, NULL);

    printf("Count : %d\n",count);

    timersub(&stimee,&stimes,&stimed);
    timersub(&ptimee,&ptimes,&ptimed);

    printf("Sequential time : %f. \n",stimed.tv_sec*1000.0 + stimed.tv_usec/1000.0);
    printf("Parallel time : %f. \n",ptimed.tv_sec*1000.0 + ptimed.tv_usec/1000.0);

    return 0;
}
예제 #2
0
//------------------------------------------------------------------------
// ttyoin -- lower-half tty device driver for output interrupts
//------------------------------------------------------------------------
void
ttyoin(struct tty *iptr)
{
	struct csr *cptr;
	int ct;

	cptr = iptr->ioaddr;
	if (iptr->ehead != iptr->etail) {
		cptr->tbufa = iptr->ebuff[iptr->etail++];
		if (iptr->etail >= EBUFLEN)
			iptr->etail = 0;
		return;
	}
	if (iptr->oheld) {	// honor flow control
		iptr->imr &= ~DUART_TxINTABLE;
		cptr->imr = iptr->imr;
		return;
	}
	if ((ct = scount(iptr->osem)) >= OBUFLEN) {
		iptr->imr &= ~DUART_TxINTABLE;
		cptr->imr = iptr->imr;
		return;
	}
	cptr->tbufa = iptr->obuff[iptr->otail++];
	if (iptr->otail >= OBUFLEN)
		iptr->otail = 0;
	if (ct > OBMINSP)
		signal(iptr->osem);
	else if (++(iptr->odsend) == OBMINSP) {
		iptr->odsend = 0;
		signaln(iptr->osem, OBMINSP);
	}
}
예제 #3
0
/*------------------------------------------------------------------------
 * ttyread - read characters from a tty
 *------------------------------------------------------------------------
 */
int
ttyread(struct devsw *pdev, char *buf, unsigned len)
{
	STATWORD	ps;
	struct tty	*ptty = (struct tty *)pdev->dvioblk;
	unsigned	count;

	if (ptty->tty_state != TTYS_ALLOC)
		return SYSERR;
	if ((ptty->tty_iflags & TIF_EOF) && ptty->tty_icount == 0) {
		ptty->tty_iflags &= ~TIF_EOF;
		return EOF;
	}
	if (ptty->tty_iflags & TIF_NOBLOCK)
		if (scount(ptty->tty_isema) <= 0)
			return SYSERR;
	disable(ps);
	wait(ptty->tty_isema);
	count = 0;
	while (count < len && ptty->tty_icount) {
		*buf++ = ptty->tty_in[ptty->tty_istart];
		count++;
		ptty->tty_icount--;
		ptty->tty_istart++;
		if (ptty->tty_istart >= IBLEN)
			ptty->tty_istart = 0;
	}
/* wakeup other readers here */
	restore(ps);
	gettime(&ptty->tty_ctime);
	return count;
}
예제 #4
0
/*------------------------------------------------------------------------
 *  ttyoin  --  lower-half tty device driver for output interrupts
 *------------------------------------------------------------------------
 */
INTPROC ttyoin( register struct tty *iptr )
{
    register struct csr *cptr;
    int ct;

    cptr = iptr->ioaddr;
    if ( iptr->ehead != iptr->etail ) {
        cptr->ctbuf = iptr->ebuff[iptr->etail++];
        cptr->ctstat = cptr->ctstat | SLUREADYON;
        if ( iptr->etail >= EBUFLEN )
            iptr->etail = 0;

        return;
    }
    if ( iptr->oheld ) { /* honor flow control	*/
        cptr->ctstat = SLUDISABLE;
        return;
    }
    if ( ( ct = scount( iptr->osem ) ) < OBUFLEN ) {
        cptr->ctbuf = iptr->obuff[iptr->otail++];
        cptr->ctstat = cptr->ctstat | SLUREADYON;
        if ( iptr->otail >= OBUFLEN )
            iptr->otail = 0;
        if ( ct > OBMINSP )
            signal( iptr->osem );
        else if ( ++( iptr->odsend ) == OBMINSP ) {
            iptr->odsend = 0;
            signaln( iptr->osem, OBMINSP );
        }

    } else {
        cptr->ctstat = SLUDISABLE;
    }
    return;
}
예제 #5
0
파일: bs.c 프로젝트: a565109863/src
int
main(int argc, char *argv[])
{
    if (pledge("stdio rpath tty", NULL) == -1)
        err(1, "pledge");

    do_options(argc, argv);

    intro();
    do {
	initgame();
	while(awinna() == -1)
	{
	    if (!blitz)
	    {
		if (!salvo)
		{
	    	    if(turn)
			(void) cputurn();
		    else
			(void) plyturn();
		}
		else  /* salvo */
		{
		    int i;

		    i = scount(turn);
		    while (i--)
		    {
			if (turn)
			{
			    if (cputurn() && awinna() != -1)
				i = 0;
			}
			else
			{
			    if (plyturn() && awinna() != -1)
				i = 0;
			}
		    }
		}
	    }
	    else  /* blitz */
	    	while(turn ? cputurn() : plyturn())
		{
		    if (turn)   /* Pause between successive computer shots */
		    {
			(void)refresh();
			(void)sleep(1);
		    }
		    if (awinna() != -1)
		     break;
		}
	    turn = OTHER;
	}
    } while
	(playagain());
    uninitgame(0);
    return 0;
}
예제 #6
0
//------------------------------------------------------------------------
//  writecopy - high-speed copy from user's buffer into system buffer
//------------------------------------------------------------------------
static int
writecopy(char *buff, struct tty *ttyp, int count)
{
	int avail;
	char *cp, *qhead, *qend, *uend;

	avail = scount(ttyp->osem);
	qhead = &ttyp->obuff[ttyp->ohead];
	qend = &ttyp->obuff[OBUFLEN];
	cp = buff;
	uend = buff + count;
	while (avail-- > 1 && cp < uend) {
		if (*cp == NEWLINE && ttyp->ocrlf) {
			*qhead++ = RETURN;
			--avail;
			if (qhead >= qend)
				qhead = ttyp->obuff;
		}
		*qhead++ = *cp++;
		if (qhead >= qend)
			qhead = ttyp->obuff;
	}			// avail decremented one
	ttyp->ohead = qhead - ttyp->obuff;	// extra time when loop
	sreset(ttyp->osem, ++avail);	// condition fails.
	ttyp->imr |= DUART_TxINTABLE;
	(ttyp->ioaddr)->imr = ttyp->imr;

	return cp - buff;
}
예제 #7
0
/*------------------------------------------------------------------------
 *  ttyread - read one or more characters from a tty device
 *------------------------------------------------------------------------
 */
int ttyread( struct devsw *devptr, char *buff, int count )
{

    register struct tty *iptr;
    int avail, nread;
    sigset_t PS;
    if ( count < 0 )
        return (SYSERR );
    disable( &PS );
    avail = scount( ( iptr = &tty[devptr->dvminor] )->isem );

    if ( ( count = ( count == 0 ? avail : count ) ) == 0 ) {
        restore( &PS );
        return (0 );
    }
    nread = count;
    if ( count <= avail ) {
        readcopy( buff, iptr, count );
    } else {
        if ( avail > 0 ) {
            readcopy( buff, iptr, avail );
            buff += avail;
            count -= avail;
        }
        for (; count > 0; count-- )
            *buff++ = ttygetc( devptr );
    }

    restore( &PS );
    return (nread );
}
예제 #8
0
int main(int argc, char *argv[])
{
	(void)argv ;
	int num_sem = (int)argc;
	printf("[Process %i] : Valeur du semaphore avant wait: %i.\n", getpid(), scount(num_sem));
	if(wait(num_sem) != 0)
	{
		printf("Erreur wait !\n");
		return -1 ;
	}
	printf("[Process %i] J'ai la main.\n", getpid());
	if(signal(num_sem) != 0)
	{
		printf("Erreur signal !\n");
		return -1 ;
	}
	printf("[Process %i] : Valeur du semaphore apres signal: %i.\n",getpid(),  scount(num_sem));
	return 0;
}
예제 #9
0
/*------------------------------------------------------------------------
 * ttyiin - handle interrupt-level input for a tty
 *------------------------------------------------------------------------
 */
void
ttyiin(struct devsw *pdev, unsigned char ch)
{
    struct tty	*ptty = (struct tty *)pdev->dvioblk;
    struct tchars	*ptc;
    static unsigned char	lastc;

    if (ch == '\n' && lastc == '\r')
        return;
    lastc = ch;
    if (ptty->tty_iflags & TIF_RAW) {
        iputchar(ptty, ch);
        if (scount(ptty->tty_isema) <= 0)
            signal(ptty->tty_isema);
        return;
    }
    if (ch == '\r')
        ch = '\n';
    ptc = &ptty->tty_tchars;
    if (ch == ptc->tc_erase) {
        delchar(ptty);
        return;
    } else if (ch == ptc->tc_werase) {
        delword(ptty);
        return;
    } else if (ch == ptc->tc_reprint) {
        reprint(ptty);
        return;
    } else if (ch == ptc->tc_intr) {
        send(ptty->tty_cpid, INTRMSG);
        return;
    } else if (ch == ptc->tc_eof) {
        ptty->tty_iflags |= TIF_EOF;
    } else if (ch == ptc->tc_status) {
        x_ps(CONSOLE, CONSOLE, CONSOLE, 0);
    }
    iputchar(ptty, ch);
    if ((ptty->tty_iflags & (TIF_CBREAK|TIF_RAW)) ||
            ch == ptty->tty_tchars.tc_eol ||
            ch == ptty->tty_tchars.tc_eof)
        if (scount(ptty->tty_isema) <= 0)
            signal(ptty->tty_isema);
}
예제 #10
0
/*------------------------------------------------------------------------
 *  readcopy - high speed copy procedure used by ttyread
 *------------------------------------------------------------------------
 */
LOCAL int readcopy( register char *buff, struct tty *iptr, int count )
{
    register char *qtail, *qend, *uend; /* copy loop variables */

    qtail = &iptr->ibuff[iptr->itail];
    qend = &iptr->ibuff[IBUFLEN];
    uend = buff + count;
    while ( buff < uend ) {
        *buff++ = *qtail++;
        if ( qtail >= qend )
            qtail = iptr->ibuff;
    }
    iptr->itail = qtail - iptr->ibuff;
    sreset( iptr->isem, scount( iptr->isem ) - count );
    return;
}
예제 #11
0
int
main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");

    do_options(argc, argv);

    intro();
    do {
	initgame();
	while (awinna() == -1) {
	    if (!blitz) {
		if (!salvo) {
		    if (turn)
			(void) cputurn();
		    else
			(void) plyturn();
		} else {
		    register int i;

		    i = scount(turn);
		    while (i--) {
			if (turn) {
			    if (cputurn() && awinna() != -1)
				i = 0;
			} else {
			    if (plyturn() && awinna() != -1)
				i = 0;
			}
		    }
		}
	    } else
		while ((turn ? cputurn() : plyturn()) && awinna() == -1)
		    continue;
	    turn = OTHER;
	}
    } while
	(playagain());
    uninitgame(0);
    /*NOTREACHED */
}
예제 #12
0
파일: x_net.c 프로젝트: 9MMMinor/avrXinu-V7
COMMAND	x_net(int nargs, int *argv)
{
	int i;

	if ( nargs > 1 )		{
		printf("%s ignore arguments: ", argv[0]);
		for (i = 1; i < nargs; i++)		{
			printf("%s%s", argv[i], (i < nargs-1) ? " " : "");
		}
		printf("\n");
	}
	printf("bpool=%d, mutex/cnt=%d/%d\n",
			Net.radiopool, Net.nmutex, scount(Net.nmutex));
	printf("Packets: Total=%d, data=%d beacon=%d mac command=%d\n",
			Net.npacket, Net.ndata, Net.nbeacon, Net.ncmd);
	printf("   Data missed: (%d no buffer space)  (%d address not matched)\n",
			Net.nover, Net.ndrop);
	printf("   Errors: %d\n", Net.nerror);
	
	return(OK);
}
예제 #13
0
int
main(int argc, char **argv)
{
    do_options(argc, argv);

    intro();
    do {
		initgame();
		while(awinna() == -1) {
		    if (!blitz) {
				if (!salvo) {
		    	    if (turn)
		    	    	cputurn();
		    	    else plyturn();
				} else {
				     register int i;

				     i = scount(turn);
				     while (i--) {
					 	if (turn)
					 	    if (cputurn())
							 	if (awinna() != -1)
							     	i = 0;
					 	else
					 	    if(plyturn())
							 	if (awinna() != -1)
							     	i = 0;
				 	}
			    }
		    } else {
		    	while((turn) ? cputurn() : plyturn());
		    }
		    turn = OTHER;
		}
    } while(playagain());
    uninitgame();
    exit(0);
}
예제 #14
0
파일: bs.c 프로젝트: kusumi/DragonFlyBSD
int
main(int argc, char **argv)
{
	int ch;

	/* revoke */
	setgid(getgid());

	while ((ch = getopt(argc, argv, "bsc")) != -1) {
		switch (ch) {
			case 'b':
				blitz = 1;
				break;
			case 's':
				salvo = 1;
				break;
			case 'c':
				closepack = 1;
				break;
			case '?':
			default:
				usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (blitz && salvo)
		usage();

    intro();

	do {
		initgame();
		while(awinna() == -1) {
			if (blitz) {
				while(turn ? cputurn() : plyturn())
					continue;
			} else if (salvo) {
				int i;

		   		i = scount(turn);
		   		while (i--) {
					if (turn) {
		   				if (cputurn() && awinna() != -1)
						i = 0;
					} else {
		   				if (plyturn() && awinna() != -1)
						i = 0;
					}
		   		}
			} else {	/* Normal game */
				if(turn)
					cputurn();
		   		else
					plyturn();
			}
	   		turn = OTHER;
		}
	} while (playagain());

    uninitgame();
    exit(0);
}
예제 #15
0
void parallelComm::sendRecvPacketsV(std::vector<VPACKET> &sndPack, std::vector<VPACKET> &rcvPack)
{
  std::vector<int> scount(2*nsend);
  std::vector<int> rcount(2*nrecv);
  std::vector<MPI_Request> request(2*(nsend+nrecv));
  std::vector<MPI_Status> status(2*(nsend+nrecv));

  for (int i = 0; i < nsend; i++) {
    scount[2*i] = sndPack[i].nints;
    scount[2*i+1] = sndPack[i].nreals;
  }

  int irnum = 0;

  for (int i = 0; i < nrecv; i++)
    MPI_Irecv(&(rcount[2*i]),2,MPI_INT,rcvMap[i],10,scomm,&request[irnum++]);

  for (int i = 0; i < nsend; i++)
    MPI_Isend(&(scount[2*i]),2,MPI_INT,sndMap[i],10,scomm,&request[irnum++]);

  MPI_Waitall(irnum,request.data(),status.data());

  for (int i = 0; i < nrecv; i++)
  {
    rcvPack[i].nints = rcount[2*i];
    rcvPack[i].nreals = rcount[2*i+1];
  }

  irnum = 0;
  for (int i = 0; i < nrecv; i++)
  {
    if (rcvPack[i].nints > 0)
    {
      rcvPack[i].intData.resize(rcvPack[i].nints);
      MPI_Irecv(rcvPack[i].intData.data(),rcvPack[i].nints,MPI_INT,
                rcvMap[i],10,scomm,&request[irnum++]);
    }

    if (rcvPack[i].nreals > 0)
    {
      rcvPack[i].realData.resize(rcvPack[i].nreals);
      MPI_Irecv(rcvPack[i].realData.data(),rcvPack[i].nreals,MPI_DOUBLE,
                rcvMap[i],20,scomm,&request[irnum++]);
    }
  }

  for (int i = 0; i < nsend;i++)
  {
    if (sndPack[i].nints > 0)
    {
      MPI_Isend(sndPack[i].intData.data(),sndPack[i].nints,MPI_INT,
                sndMap[i],10,scomm,&request[irnum++]);
    }
    if (sndPack[i].nreals > 0)
    {
      MPI_Isend(sndPack[i].realData.data(),sndPack[i].nreals,MPI_DOUBLE,
                sndMap[i],20,scomm,&request[irnum++]);
    }
  }
  MPI_Waitall(irnum,request.data(),status.data());
}
예제 #16
0
int main(void *arg)
{
        int sem, i;

        (void)arg;

        assert(screate(-2) == -1);
        assert((sem = screate(2)) >= 0);
        assert(signaln(sem, -4) < 0);
        assert(sreset(sem, -3) == -1);
        assert(scount(sem) == 2);
        assert(signaln(sem, 32760) == 0);
        assert(signaln(sem, 6) == -2);
        assert(scount(sem) == 32762);
        assert(wait(sem) == 0);
        assert(scount(sem) == 32761);
        assert(signaln(sem, 30000) == -2);
        assert(scount(sem) == 32761);
        assert(wait(sem) == 0);
        assert(scount(sem) == 32760);
        assert(signaln(sem, -2) < 0);
        assert(scount(sem) == 32760);
        assert(wait(sem) == 0);
        assert(scount(sem) == 32759);
        assert(signaln(sem, 8) == 0);
        assert(scount(sem) == 32767);
        assert(signaln(sem, 1) == -2);
        assert(scount(sem) == 32767);
        assert(signal(sem) == -2);
        assert(scount(sem) == 32767);
        for (i=0; i<32767; i++) {
                assert(wait(sem) == 0);
        }
        assert(try_wait(sem) == -3);
        assert(scount(sem) == 0);
        assert(sdelete(sem) == 0);
        printf("ok.\n");
}