Exemplo n.º 1
0
int main(int argc, char **argv){
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);
	
	mi_init(argc, argv);
	
	printf("enter barrier\n");
	mi_barrier();
	printf("exit barrier\n");

	int i, j;
	int *result = (int *)mi_alloc(sizeof(int));
	printf("enter barrier\n");
	mi_barrier();
	printf("exit barrier\n");

	for(i = 0; i < 3000; i++){	
		printf("before lock\n");
		mi_lock(0);
		printf("after lock\n");
		*result = *result + 1;
		printf("before unlock\n");
		mi_unlock(0);
		printf("after unlock\n");
	}
	
	printf("enter barrier\n");
	mi_barrier();
	printf("exit barrier\n");
	printf("result = %d\n", *result);
	mi_barrier();
	showDataStructures();
}
Exemplo n.º 2
0
struct mif *mi_open(char *iface)
{
    struct mif *mi;
    struct priv_if *pi;
    pcap_t *pkt_in, *pkt_out;
    char errbuf[PCAP_ERRBUF_SIZE];

    /* setup mi struct */
    mi = mi_alloc(sizeof(*pi));
    if (!mi)
        return NULL;

    mi->read  = mi_read;
    mi->write = mi_write;
    mi->close = mi_close;

    // for pkt in
    pkt_in = pcap_open_live(iface, 4096, 1, 10, errbuf);
    if (pkt_in == NULL) {
        printf("Unable to open interface %s in pcap: %s\n", iface, errbuf);
        return NULL;
    }

    if (pcap_datalink(pkt_in) != DLT_IEEE802_11_RADIO) {
        printf("Device %s doesn't provide 80211 radiotap header\n", iface);
        return NULL;
    }

    if (pcap_setnonblock(pkt_in, 1, errbuf) == -1) {
        printf("Device %s doesn't set non-blocking mode\n", iface);
        return NULL;
    }

    // for pkt out
    pkt_out = pcap_open_live(iface, 4096, 1, 10, errbuf);
    if (pkt_out == NULL) {
        printf("Unable to open interface %s in pcap: %s\n", iface, errbuf);
        return NULL;
    }

    pi = mi_priv(mi);
    pi->fd_in = pkt_in;
    pi->fd_out = pkt_out;

    return mi;
}
Exemplo n.º 3
0
Arquivo: mm.c Projeto: ZeyuMi/MiDSM
int main(int argc, char **argv)
{
	int x, y, z, p, magic;
	int error;
	int (*local)[N] = (int (*)[N])malloc(N * N * sizeof(int));

	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);
	mi_init(argc, argv);

	mi_barrier();

	a = (int (*)[N])mi_alloc(N * N * sizeof(int));
	b = (int (*)[N])mi_alloc(N * N * sizeof(int));
	c = (int (*)[N])mi_alloc(N * N * sizeof(int));

	printf("Memory Allocation Done\n");

	printf("starting barrier\n");
	mi_barrier();
	printf("exiting barrier\n"); 

	printf("Initializing matrices ....................\n");
	mi_lock(0);
	seqinit();
	mi_unlock(0);
	printf("Initializing matrices done!\n");

	printf("starting barrier 2\n");
	mi_barrier();
	printf("exiting barrier 2\n");

	magic = N / hostnum;

	for (x = myhostid * magic; x < (myhostid + 1) * magic; x++){
		printf("x = %d\n",x);
		for (y = 0; y < N; y++)
			for (z = 0; z < N; z++)
				local[y][z] += (a[x][y] * b[x][z]);
		printf("x = %d done\n",x);
	}

	printf("starting barrier 3\n");
	mi_barrier();
	printf("exiting barrier 3\n");

	for (x = 0; x < hostnum; x++) 
	{
		p = (myhostid + x) % hostnum;
		printf("lock %d\n", p);
		mi_lock(p);
		printf("lock %d done\n", p);
		for (y = p * magic; y < (p + 1) * magic; y++)
		{  
			for (z = 0; z < N; z++)
			{  if (x == 0) c[y][z] = local[y][z];
				else c[y][z] += local[y][z];
			}
		}
		printf("unlock %d\n", p);
		mi_unlock(p);
		printf("unlock %d done\n", p);
		if (x == 0) mi_barrier();
	}
//	mi_lock(0);
//	for(x = 0; x < N; x++){
//		for(y = 0; y < N; y++){
//			c[x][y] += local[x][y];
//		}
//	}
//	mi_unlock(0);

	mi_barrier();


	if (myhostid == 0)
	{
		error = 0;
		for (x = 0; x < hostnum; x++)
		{
			mi_lock(x);
			for (y = x * magic; y < (x + 1) * magic; y++)
			{
				for (z = 0; z < N; z++)
				{
					if (c[y][z] != N) 
					{  error = 1;
						printf("ERROR: y = %d, z = %d, c = %d\n", y, z, c[y][z]);
					}
				}
			}
			mi_unlock(x);
		}
		if (error == 1) 
			printf("NOTE: There is some error in the program!\n");
	}
	printf("program will exit\n");
	mi_barrier();
}