浏览代码

mpi load balancer: add test for lb initialization

Nathalie Furmento 8 年之前
父节点
当前提交
86786094be

+ 3 - 3
mpi/include/starpu_mpi_lb.h

@@ -24,9 +24,9 @@ extern "C" {
 
 
 struct starpu_mpi_lb_conf
 struct starpu_mpi_lb_conf
 {
 {
-    void (*get_neighbors)(int **neighbor_ids, int *nneighbors);
-    void (*get_data_unit_to_migrate)(starpu_data_handle_t **handle_unit, int *nhandles, int dst_node);
-    const char *name;
+	void (*get_neighbors)(int **neighbor_ids, int *nneighbors);
+	void (*get_data_unit_to_migrate)(starpu_data_handle_t **handle_unit, int *nhandles, int dst_node);
+	const char *name;
 };
 };
 
 
 /* Inits the load balancer's environment with the load policy provided by the
 /* Inits the load balancer's environment with the load policy provided by the

+ 12 - 6
mpi/src/load_balancer/load_balancer.c

@@ -20,6 +20,7 @@
 #include <starpu.h>
 #include <starpu.h>
 #include <starpu_mpi.h>
 #include <starpu_mpi.h>
 #include <starpu_scheduler.h>
 #include <starpu_scheduler.h>
+#include <common/utils.h>
 
 
 #include <starpu_mpi_lb.h>
 #include <starpu_mpi_lb.h>
 #include "policy/load_balancer_policy.h"
 #include "policy/load_balancer_policy.h"
@@ -44,15 +45,17 @@ static struct load_balancer_policy *predefined_policies[] =
 
 
 void starpu_mpi_lb_init(struct starpu_mpi_lb_conf *itf)
 void starpu_mpi_lb_init(struct starpu_mpi_lb_conf *itf)
 {
 {
+	int ret;
+
 	const char *policy_name = starpu_getenv("STARPU_MPI_LB");
 	const char *policy_name = starpu_getenv("STARPU_MPI_LB");
 	if (!policy_name && itf)
 	if (!policy_name && itf)
 		policy_name = itf->name;
 		policy_name = itf->name;
 
 
 	if (!policy_name || (strcmp(policy_name, "help") == 0))
 	if (!policy_name || (strcmp(policy_name, "help") == 0))
 	{
 	{
-		fprintf(stderr,"Warning : load balancing is disabled for this run.\n");
-		fprintf(stderr,"Use the STARPU_MPI_LB = <name> environment variable to use a load balancer.\n");
-		fprintf(stderr,"Available load balancers :\n");
+		_STARPU_MSG("Warning : load balancing is disabled for this run.\n");
+		_STARPU_MSG("Use the STARPU_MPI_LB = <name> environment variable to use a load balancer.\n");
+		_STARPU_MSG("Available load balancers :\n");
 		struct load_balancer_policy **policy;
 		struct load_balancer_policy **policy;
 		for(policy=predefined_policies ; *policy!=NULL ; policy++)
 		for(policy=predefined_policies ; *policy!=NULL ; policy++)
 		{
 		{
@@ -82,13 +85,14 @@ void starpu_mpi_lb_init(struct starpu_mpi_lb_conf *itf)
 
 
 	if (!defined_policy)
 	if (!defined_policy)
 	{
 	{
-		fprintf(stderr,"Error : no load balancer with the name %s. Load balancing will be disabled for this run.\n", policy_name);
+		_STARPU_MSG("Error : no load balancer with the name %s. Load balancing will be disabled for this run.\n", policy_name);
 		return;
 		return;
 	}
 	}
 
 
-	if (defined_policy->init(itf) != 0)
+	ret = defined_policy->init(itf);
+	if (ret != 0)
 	{
 	{
-		fprintf(stderr,"Error in load_balancer->init: invalid starpu_mpi_lb_conf. Load balancing will be disabled for this run.\n");
+		_STARPU_MSG("Error (%d) in %s->init: invalid starpu_mpi_lb_conf. Load balancing will be disabled for this run.\n", ret, defined_policy->policy_name);
 		return;
 		return;
 	}
 	}
 
 
@@ -119,6 +123,8 @@ void starpu_mpi_lb_init(struct starpu_mpi_lb_conf *itf)
 		}
 		}
 		starpu_sched_policy_set_post_exec_hook(post_exec_hook_wrapper, sched_policy_name);
 		starpu_sched_policy_set_post_exec_hook(post_exec_hook_wrapper, sched_policy_name);
 	}
 	}
+
+	return;
 }
 }
 
 
 void starpu_mpi_lb_shutdown()
 void starpu_mpi_lb_shutdown()

+ 5 - 0
mpi/src/load_balancer/policy/load_heat_propagation.c

@@ -17,6 +17,7 @@
 
 
 #include <starpu_mpi.h>
 #include <starpu_mpi.h>
 #include <common/uthash.h>
 #include <common/uthash.h>
+#include <common/utils.h>
 #include <math.h>
 #include <math.h>
 
 
 #include "load_balancer_policy.h"
 #include "load_balancer_policy.h"
@@ -409,7 +410,10 @@ static int init_heat(struct starpu_mpi_lb_conf *itf)
 
 
 	/* Immediately return if the starpu_mpi_lb_conf is invalid. */
 	/* Immediately return if the starpu_mpi_lb_conf is invalid. */
 	if (!(itf && itf->get_neighbors && itf->get_data_unit_to_migrate))
 	if (!(itf && itf->get_neighbors && itf->get_data_unit_to_migrate))
+	{
+		_STARPU_MSG("Error: struct starpu_mpi_lb_conf %p invalid\n", itf);
 		return 1;
 		return 1;
+	}
 
 
 	user_itf = malloc(sizeof(struct starpu_mpi_lb_conf));
 	user_itf = malloc(sizeof(struct starpu_mpi_lb_conf));
 	memcpy(user_itf, itf, sizeof(struct starpu_mpi_lb_conf));;
 	memcpy(user_itf, itf, sizeof(struct starpu_mpi_lb_conf));;
@@ -418,6 +422,7 @@ static int init_heat(struct starpu_mpi_lb_conf *itf)
 	user_itf->get_neighbors(&neighbor_ids, &nneighbors);
 	user_itf->get_neighbors(&neighbor_ids, &nneighbors);
 	if (nneighbors == 0)
 	if (nneighbors == 0)
 	{
 	{
+		_STARPU_MSG("Error: Function get_neighbors returning 0 neighbor\n");
 		free(user_itf);
 		free(user_itf);
 		user_itf = NULL;
 		user_itf = NULL;
 		return 2;
 		return 2;

+ 7 - 3
mpi/tests/Makefile.am

@@ -1,7 +1,7 @@
 # StarPU --- Runtime system for heterogeneous multicore architectures.
 # StarPU --- Runtime system for heterogeneous multicore architectures.
 #
 #
 # Copyright (C) 2009-2012, 2015-2016  Université de Bordeaux
 # Copyright (C) 2009-2012, 2015-2016  Université de Bordeaux
-# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016  CNRS
+# Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017  CNRS
 #
 #
 # StarPU is free software; you can redistribute it and/or modify
 # StarPU is free software; you can redistribute it and/or modify
 # it under the terms of the GNU Lesser General Public License as published by
 # it under the terms of the GNU Lesser General Public License as published by
@@ -138,7 +138,8 @@ starpu_mpi_TESTS =				\
 	policy_selection			\
 	policy_selection			\
 	policy_selection2			\
 	policy_selection2			\
 	early_request				\
 	early_request				\
-	starpu_redefine
+	starpu_redefine				\
+	load_balancer
 
 
 noinst_PROGRAMS =				\
 noinst_PROGRAMS =				\
 	datatypes				\
 	datatypes				\
@@ -191,7 +192,8 @@ noinst_PROGRAMS =				\
 	policy_selection			\
 	policy_selection			\
 	policy_selection2			\
 	policy_selection2			\
 	early_request				\
 	early_request				\
-	starpu_redefine
+	starpu_redefine				\
+	load_balancer
 
 
 
 
 XFAIL_TESTS=					\
 XFAIL_TESTS=					\
@@ -301,6 +303,8 @@ early_request_LDADD =					\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 starpu_redefine_LDADD =					\
 starpu_redefine_LDADD =					\
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
+load_balancer_LDADD =					\
+	../src/libstarpumpi-@STARPU_EFFECTIVE_VERSION@.la
 
 
 ring_SOURCES = ring.c
 ring_SOURCES = ring.c
 ring_sync_SOURCES = ring_sync.c
 ring_sync_SOURCES = ring_sync.c

+ 74 - 0
mpi/tests/load_balancer.c

@@ -0,0 +1,74 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2017  CNRS
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#include <starpu_mpi.h>
+#include <starpu_mpi_lb.h>
+#include "helper.h"
+
+#if !defined(STARPU_HAVE_SETENV) && !defined(STARPU_HAVE_UNSETENV)
+
+#warning setenv and unsetenv are not defined. Skipping test
+int main(int argc, char **argv)
+{
+	return STARPU_TEST_SKIPPED;
+}
+#else
+
+void get_neighbors(int **neighbor_ids, int *nneighbors)
+{
+	int ret, rank, size;
+	starpu_mpi_comm_rank(MPI_COMM_WORLD, &rank);
+	starpu_mpi_comm_size(MPI_COMM_WORLD, &size);
+	*nneighbors = 1;
+	*neighbor_ids = malloc(sizeof(int));
+	*neighbor_ids[0] = rank==size-1?0:rank+1;
+}
+
+void get_data_unit_to_migrate(starpu_data_handle_t **handle_unit, int *nhandles, int dst_node)
+{
+	STARPU_ASSERT(0);
+}
+
+int main(int argc, char **argv)
+{
+	int ret;
+	struct starpu_mpi_lb_conf itf;
+
+	itf.get_neighbors = get_neighbors;
+	itf.get_data_unit_to_migrate = get_data_unit_to_migrate;
+	itf.name = "my_itf";
+
+	MPI_Init(&argc, &argv);
+	ret = starpu_init(NULL);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
+	ret = starpu_mpi_init(NULL, NULL, 0);
+	STARPU_CHECK_RETURN_VALUE(ret, "starpu_mpi_init");
+
+	unsetenv("STARPU_MPI_LB");
+	starpu_mpi_lb_init(NULL);
+	starpu_mpi_lb_shutdown();
+
+	setenv("STARPU_MPI_LB", "heat", 1);
+	starpu_mpi_lb_init(&itf);
+
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+	MPI_Finalize();
+
+	return 0;
+}
+
+#endif