Explorar o código

- Fix typos in the starpu_mpi_test function
- Remove an erroneous mutex release in the progression loop
- Add a test using starpu_mpi_test

Cédric Augonnet %!s(int64=15) %!d(string=hai) anos
pai
achega
2cd39cd63a
Modificáronse 3 ficheiros con 92 adicións e 11 borrados
  1. 7 0
      mpi/Makefile.am
  2. 5 11
      mpi/starpu_mpi.c
  3. 80 0
      mpi/tests/mpi_test.c

+ 7 - 0
mpi/Makefile.am

@@ -48,6 +48,7 @@ mpiexamplebindir=$(libdir)/starpu/mpi/
 
 mpiexamplebin_PROGRAMS =				\
 	tests/pingpong					\
+	tests/mpi_test					\
 	tests/mpi_isend					\
 	tests/mpi_irecv					\
 	tests/ring					\
@@ -73,6 +74,12 @@ tests_pingpong_LDADD =					\
 tests_pingpong_SOURCES =				\
 	tests/pingpong.c
 
+tests_mpi_test_LDADD =					\
+	libstarpumpi.la
+
+tests_mpi_test_SOURCES =				\
+	tests/mpi_test.c
+
 tests_ring_LDADD =					\
 	libstarpumpi.la
 

+ 5 - 11
mpi/starpu_mpi.c

@@ -237,11 +237,6 @@ static void starpu_mpi_test_func(struct starpu_mpi_req_s *testing_req)
 int starpu_mpi_test(struct starpu_mpi_req_s *req, int *flag, MPI_Status *status)
 {
 	int ret = 0;
-	struct starpu_mpi_req_s testing_req;
-
-	memset(&testing_req, 0, sizeof(struct starpu_mpi_req_s));
-
-	pthread_mutex_lock(&req->req_mutex);
 
 	STARPU_ASSERT(!req->detached);
 
@@ -251,13 +246,16 @@ int starpu_mpi_test(struct starpu_mpi_req_s *req, int *flag, MPI_Status *status)
 
 	if (submitted)
 	{
+		struct starpu_mpi_req_s testing_req;
+		memset(&testing_req, 0, sizeof(struct starpu_mpi_req_s));
+
 		/* Initialize the request structure */
 		pthread_mutex_init(&testing_req.req_mutex, NULL);
 		pthread_cond_init(&testing_req.req_cond, NULL);
 		testing_req.flag = flag;
 		testing_req.status = status;
 		testing_req.other_request = req;
-		testing_req.func = starpu_mpi_wait_func;
+		testing_req.func = starpu_mpi_test_func;
 		testing_req.completed = 0;
 		
 		submit_mpi_req(&testing_req);
@@ -332,9 +330,6 @@ void *progress_thread_func(void *arg __attribute__((unused)))
 		if (!running)
 			break;		
 
-		/* Handle new requests  */
-	//	while (req = starpu_mpi_req_list_pop_back(new_requests))
-
 		/* get one request */
 		struct starpu_mpi_req_s *req;
 		while (!starpu_mpi_req_list_empty(new_requests))
@@ -349,9 +344,8 @@ void *progress_thread_func(void *arg __attribute__((unused)))
 			handle_new_request(req);
 			pthread_mutex_lock(&mutex);
 		}
-
-		pthread_mutex_unlock(&mutex);
 	}
+
 	pthread_mutex_unlock(&mutex);
 
 	return NULL;

+ 80 - 0
mpi/tests/mpi_test.c

@@ -0,0 +1,80 @@
+/*
+ * StarPU
+ * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
+ *
+ * This program 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.
+ *
+ * This program 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>
+
+#define NITER	2048
+#define SIZE	16
+
+float *tab;
+starpu_data_handle tab_handle;
+
+int main(int argc, char **argv)
+{
+	MPI_Init(NULL, NULL);
+
+	int rank, size;
+
+	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+	MPI_Comm_size(MPI_COMM_WORLD, &size);
+
+	if (size != 2)
+	{
+		if (rank == 0)
+			fprintf(stderr, "We need exactly 2 processes.\n");
+
+		MPI_Finalize();
+		return 0;
+	}
+
+	starpu_init(NULL);
+	starpu_mpi_initialize();
+
+	tab = malloc(SIZE*sizeof(float));
+
+	starpu_register_vector_data(&tab_handle, 0, (uintptr_t)tab, SIZE, sizeof(float));
+
+	unsigned nloops = NITER;
+	unsigned loop;
+
+	int other_rank = (rank + 1)%2;
+
+	for (loop = 0; loop < nloops; loop++)
+	{
+		struct starpu_mpi_req_s req;
+
+		if ((loop % 2) == rank)
+		{
+                        starpu_mpi_isend(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
+		}
+		else {
+			starpu_mpi_irecv(tab_handle, &req, other_rank, loop, MPI_COMM_WORLD);
+		}
+
+		int finished = 0;
+		do {
+			MPI_Status status;
+			starpu_mpi_test(&req, &finished, &status);
+		} while (!finished);
+	}
+	
+	starpu_mpi_shutdown();
+	starpu_shutdown();
+
+	MPI_Finalize();
+
+	return 0;
+}