Ejemplo n.º 1
0
void SpikingGroup::init(NeuronID n, double loadmultiplier, NeuronID total )
{
	group_name = "SpikingGroup";
	unique_id  = unique_id_count++;
	size = n;
	effective_load_multiplier = loadmultiplier;

	if ( total > 0 ) {
		anticipated_total = total;
		stringstream oss;
		oss << get_name() << ":: Anticipating " << anticipated_total << " units in total." ;
		logger->msg(oss.str(),NOTIFICATION);
	}

	// setting up default values
	evolve_locally_bool = true;
	locked_rank = 0;
	locked_range = communicator->size();
	rank_size = calculate_rank_size(); // set the rank size

	double fraction = (double)calculate_rank_size(0)*effective_load_multiplier/DEFAULT_MINDISTRIBUTEDSIZE;

	if ( anticipated_total > 0 )
		fraction = (1.*size*effective_load_multiplier)/anticipated_total;

	if ( fraction >= 0 && fraction < 1. ) { 
		lock_range( fraction );
	} else { // ROUNDROBIN which is default
		locked_rank = 0;
		locked_range = communicator->size();

		stringstream oss;
		oss << get_name() << ":: Size " << get_rank_size() << " (ROUNDROBIN)";
		logger->msg(oss.str(),NOTIFICATION);
	}

	stringstream oss;
	oss << get_name() << ":: Registering delay (MINDELAY=" << MINDELAY << ")";
	logger->msg(oss.str(),DEBUG);

	delay = new SpikeDelay( );
	set_delay(MINDELAY+1); 

	evolve_locally_bool = evolve_locally_bool && ( get_rank_size() > 0 );
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	char *lockfile;
	int fd;
	if (argc < 3) {
		usage();
		exit(1);
	}

	lockfile = argv[1];

	fd = open(lockfile, O_CREAT|O_RDWR, 0644);
	if (fd == -1) {
		perror(lockfile);
		exit(1);
	}

	if (lock_range(fd, 0, 1) != 0) {
		perror(lockfile);
		exit(2);
	}

	return execvp(argv[2], argv+2);
}
Ejemplo n.º 3
0
/* run the ping pong test on fd */
static void ping_pong(int fd, int num_locks)
{
	unsigned count = 0;
	int i=0, loops=0;
	unsigned char *val;
	unsigned char incr=0, last_incr=0;
	unsigned char *p = NULL;

	ftruncate(fd, num_locks+1);

	if (use_mmap) {
		p = mmap(NULL, num_locks+1, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
	}

	val = (unsigned char *)calloc(num_locks+1, sizeof(unsigned char));

	start_timer();	

	lock_range(fd, 0, 1);
	i = 0;

	while (1) {
		if (lock_range(fd, (i+1) % num_locks, 1) != 0) {
			printf("lock at %d failed! - %s\n",
			       (i+1) % num_locks, strerror(errno));
		}
		if (do_reads) {
			unsigned char c;
			if (use_mmap) {
				c = p[i];
			} else if (pread(fd, &c, 1, i) != 1) {
				printf("read failed at %d\n", i);
			}
			incr = c - val[i];
			val[i] = c;
		}
		if (do_writes) {
			char c = val[i] + 1;
			if (use_mmap) {
				p[i] = c;
			} else if (pwrite(fd, &c, 1, i) != 1) {
				printf("write failed at %d\n", i);
			}
		}
		if (unlock_range(fd, i, 1) != 0) {
			printf("unlock at %d failed! - %s\n",
			       i, strerror(errno));
		}
		i = (i+1) % num_locks;
		count++;
		if (loops > num_locks && incr != last_incr) {
			last_incr = incr;
			printf("data increment = %u\n", incr);
			fflush(stdout);
		}
		if (end_timer() > 1.0) {
			printf("%8u locks/sec\r", 
			       (unsigned)(2*count/end_timer()));
			fflush(stdout);
			start_timer();
			count=0;
		}
		loops++;
	}
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	char *fname;
	int fd, num_locks;
	int c;

	while ((c = getopt(argc, argv, "rwmcl")) != -1) {
		switch (c){
		case 'w':
			do_writes = 1;
			break;
		case 'r':
			do_reads = 1;
			break;
		case 'm':
			use_mmap = 1;
			break;
		case 'c':
			do_check = 1;
			break;
		case 'l':
			do_brl_test = 1;
			break;
		default:
			fprintf(stderr, "Unknown option '%c'\n", c);
			exit(1);
		}
	}

	argv += optind;
	argc -= optind;

	if (argc < 1) {
		usage();
		exit(1);
	}

	fname = argv[0];

	fd = open(fname, O_CREAT|O_RDWR, 0600);
	if (fd == -1) {
		exit(1);
	}

	if (do_brl_test) {
		if (lock_range(fd, 0, 0, false) != 0) {
			printf("file already locked, calling check_lock to tell us who has it locked:\n");
			(void)check_lock(fd, 0, 0);
			printf("Working POSIX byte range locks\n");
			exit(0);
		}

		printf("Holding lock, press any key to continue...\n");
		printf("You should run the same command on another node now.\n");
		(void)getchar();
		printf("Good bye.\n");
		exit(0);
	}

	if (argc < 2) {
		usage();
		exit(1);
	}

	num_locks = atoi(argv[1]);
	if (num_locks <= 0) {
		printf("num_locks should be > 0\n");
		exit(1);
	}

	ping_pong(fd, num_locks);

	return 0;
}