int main(int argc, char **argv)
{
	cluster_t *cluster;
	int result;
	int nodes;
	char *str;
	int str_len;
	int data;

	// parse the command-line parameters.
	parse_params(argc, argv);
	
	// Initialising the cluster library
	cluster = cluster_init();
	
	// Adding node to the server list
	assert(_node);
	cluster_addserver(cluster, _node);
	
	nodes = cluster_connect(cluster);
	if (nodes <= 0) {
		fprintf(stderr, "Unable to connect to %s.", _node);
		cluster_free(cluster);
		exit(1);
	}
	else {
	
		// set an item in the cluster with some data.

		if (_key_s && _integer > 0) {
			// string key, integer value;

			data = 0;
 			result = cluster_getint(cluster, _key_s, &data);
 			assert(result == 0);
			printf ("%d\n", data);
		}
		else if (_key_s && _integer == 0) {
			result = cluster_getstr(cluster, _key_s, &str, &str_len);
			assert(result == 0);
			assert(str);
			assert(str_len > 0);
			printf("%s\n", str);
			free(str);
			str = NULL;
		}
		else {
			// we need to code in the other options.
			assert(0);
		}

		// Disconnecting from the cluster
		cluster_disconnect(cluster);		
	}
	
	// Shutting down
	cluster_free(cluster);
	
	return(0);
}
示例#2
0
int main(int argc,
		 char const ** argv)
{
	if (argc < 2)
		return 1;

	unsigned int	n = atoi(argv[1]);
	cluster_t *		cluster;
	counter_ctx_t	contexts[n];
	void *			pcontexts[n];

	for (unsigned int i = 0; i < n; ++i)
	{
		contexts[i].value = 0;
		pcontexts[i] = &contexts[i];
	}

	cluster = cluster_new(n, pcontexts);
	cluster_map(cluster, map);

	for (unsigned int i = 0; i < n; ++i)
	{
		printf("map: %d == %d?\n", contexts[i].value, i + 1);
		assert(contexts[i].value == i + 1);
	}

	counter_ctx_t * res = cluster_reduce(cluster, reduce);

	printf("reduce: %d == %d?\n", res->value, sum(n));
	assert(res->value == sum(n));

	cluster_free(cluster);
}
/* parser for necklace cluster analyzation:
   analyze necklace <pearl_treshold> <back_dist> <space_dist> <first> <length> 
 */
int tclcommand_analyze_parse_necklace(Tcl_Interp *interp, int argc, char **argv)
{
  double space_dist;
  int first,length;
  Particle *part;
  Cluster *cluster;
  char buffer[TCL_INTEGER_SPACE];
  int n_pearls;

  /* check # of parameters */
  if (argc < 5) {
    Tcl_AppendResult(interp, "analyze necklace needs 5 parameters:\n", (char *)NULL);
    Tcl_AppendResult(interp, "<pearl_treshold> <back_dist> <space_dist> <first> <length>", (char *)NULL);
    return TCL_ERROR;
  }

  /* check parameter types */
  if( (! ARG_IS_I(0, pearl_treshold)) ||
      (! ARG_IS_I(1, backbone_distance))  ||
      (! ARG_IS_D(2, space_dist))     ||
      (! ARG_IS_I(3, first))          ||
      (! ARG_IS_I(4, length)) ) {
    Tcl_AppendResult(interp, "analyze necklace needs 5 parameters of type and meaning:\n", (char *)NULL);
    Tcl_AppendResult(interp, "INT INT DOUBLE INT INT\n", (char *)NULL);
    Tcl_AppendResult(interp, "<pearl_treshold> <back_dist> <space_dist> <first> <length>", (char *)NULL);
    return TCL_ERROR;
  }

  /* check parameter values */
  if( pearl_treshold < 10 ) {
    Tcl_AppendResult(interp, "analyze necklace: pearl_treshold should be >= 10", (char *)NULL);
    return TCL_ERROR;
  }
  if( backbone_distance < 2 ) {
    Tcl_AppendResult(interp, "analyze necklace: backbone_dist should be >= 2", (char *)NULL);
    return TCL_ERROR;
  }
  if( space_dist <= 0.0 ) {
    Tcl_AppendResult(interp, "analyze necklace: space_dist must be positive", (char *)NULL);
    return TCL_ERROR;
  }
  if( first < 0 ) {
    Tcl_AppendResult(interp, "analyze necklace: identity of first particle can not be negative", (char *)NULL);
    return TCL_ERROR;
  }
  if( first+length > n_part+1) {
    Tcl_AppendResult(interp, "analyze necklace: identity of last particle out of partCfg array", (char *)NULL);
    return TCL_ERROR;
  }

  /* preparation */
  space_distance2 = SQR(space_dist);
  sortPartCfg();
  part = &partCfg[first];

  /* perform necklace cluster algorithm */
  n_pearls = analyze_necklace(part, length) ;

  /* Append result to tcl interpreter */
  sprintf(buffer,"%d",n_pearls);
  Tcl_AppendResult(interp, buffer, " pearls { ", (char *)NULL);
  if( n_pearls > 0 ) {
    cluster = first_cluster;
    sprintf(buffer,"%d",cluster->size);
    Tcl_AppendResult(interp, buffer, " ",(char *)NULL);
    cluster = cluster->next;
    while(cluster->prev != last_cluster) { 
      sprintf(buffer,"%d",cluster->size);
      Tcl_AppendResult(interp, buffer, " ",(char *)NULL);
      cluster = cluster->next;
    }
  }
  Tcl_AppendResult(interp, "} ", (char *)NULL);

   /* free analyzation memory */
  cluster_free();
  
  return (TCL_OK);
}
示例#4
0
int main(int argc, char **argv)
{
	cluster_t *cluster;
	GTimer *timer;
	int data;
	int result;
	int nodes;
	register int i;
	gdouble sec;
	gulong msec;
	char *str;
	int str_len;
	char key_buffer[128];

	timer = g_timer_new();
	
	printf("Initialising the cluster library\n");
	cluster = cluster_init();
	
	printf("Adding 127.0.0.1:13600 to the server list.\n");
	cluster_addserver(cluster, "127.0.0.1:13600");
	
	nodes = cluster_connect(cluster);
	printf("Connected servers: %d\n", nodes);
	
	if (nodes > 0) {
	
		// set an item in the cluster with some data.
		printf("Setting data in the cluster (integer)\n");
		cluster_setint(cluster, "testdata", 45, 0);

		// set an item in the cluster with some data.
		printf("Setting data in the cluster (string)\n");
		cluster_setstr(cluster, "clientname", "Bill Grady", 0);

		printf("Getting str data from the cluster\n");
		result = cluster_getstr(cluster, "clientname", &str, &str_len);
		assert(result == 0);
		assert(str);
		assert(str_len > 0);
		printf("result='%s'\n", str);
		free(str);
		str = NULL;
		
		// pull some data out of the cluster.
// 		data = 0;
// 		printf("Getting data from the cluster.\n");
// 		g_timer_start(timer);
// 		for (i=0; i<GET_LIMIT; i++) {
// 			result = cluster_getint(cluster, "testdata", &data);
// 			assert(result == 0);
// 		}
// 		g_timer_stop(timer);
// 		printf ("Result of 'testdata' in cache.  data=%d\n", data);
// 		sec = g_timer_elapsed(timer, &msec);
// 		printf("Timing of %d gets. %f\n", GET_LIMIT, sec);
		
		printf("Setting 6000 items of data\n");
		g_timer_start(timer);
		for (i=0; i<6000; i++) {
			sprintf(key_buffer, "client:%d", i);
			cluster_setstr(cluster, key_buffer, "Bill Grady", 0);
		}
		g_timer_stop(timer);
		sec = g_timer_elapsed(timer, &msec);
		printf("Timing of 6000 sets. %lf\n", sec);
		
 		sleep(1);
		
		printf("Disconnecting from the cluster,\n");
		cluster_disconnect(cluster);		
	}
	
	printf("Shutting down\n");
	cluster_free(cluster);
	
	
	return(0);
}