瀏覽代碼

Start to implement starpu_mpi_handle_to_datatype.

Cédric Augonnet 15 年之前
父節點
當前提交
bf8bb00b8a
共有 4 個文件被更改,包括 86 次插入16 次删除
  1. 9 1
      mpi/Makefile.am
  2. 3 15
      mpi/starpu_mpi.c
  3. 50 0
      mpi/starpu_mpi_datatype.c
  4. 24 0
      mpi/starpu_mpi_datatype.h

+ 9 - 1
mpi/Makefile.am

@@ -34,9 +34,17 @@ AM_CPPFLAGS = -I$(top_srcdir)/include/ -I$(top_srcdir)/mpi/ -I$(top_srcdir)/src/
 
 lib_LTLIBRARIES = libstarpumpi.la
 
-libstarpumpi_la_SOURCES = starpu_mpi.c
 libstarpumpi_la_LIBADD = $(top_builddir)/src/libstarpu.la
 
+noinst_HEADERS =					\
+	starpu_mpi.h					\
+	starpu_mpi_datatype.h
+
+libstarpumpi_la_SOURCES =				\
+	starpu_mpi.c					\
+	starpu_mpi_datatype.c
+
+
 TESTS = $(check_PROGRAMS)
 
 check_PROGRAMS =

+ 3 - 15
mpi/starpu_mpi.c

@@ -15,24 +15,12 @@
  */
 
 #include <starpu_mpi.h>
+#include <starpu_mpi_datatype.h>
 
 pthread_cond_t cond;
 pthread_mutex_t mutex;
 pthread_t progress_thread;
 
-static int handle_to_datatype(starpu_data_handle data_handle, MPI_Datatype *datatype)
-{
-	/* TODO we assume that we have a vector yet ! */
-
-	unsigned nx = starpu_get_vector_nx(data_handle);
-	size_t elemsize = starpu_get_vector_elemsize(data_handle);
-
-	MPI_Type_contiguous(nx*elemsize, MPI_BYTE, datatype);
-	MPI_Type_commit(datatype);
-
-	return 0;
-}
-
 int starpu_mpi_isend(starpu_data_handle data_handle, starpu_mpi_req_t *req,
 		int dest, int mpi_tag, MPI_Comm comm,
 		void (*callback)(void *))
@@ -58,7 +46,7 @@ int starpu_mpi_recv(starpu_data_handle data_handle,
 	
 	MPI_Status status;
 	MPI_Datatype datatype;
-	handle_to_datatype(data_handle, &datatype);
+	starpu_mpi_handle_to_datatype(data_handle, &datatype);
 	MPI_Recv(ptr, 1, datatype, source, mpi_tag, comm, &status);
 
 	starpu_release_data_from_mem(data_handle);
@@ -77,7 +65,7 @@ int starpu_mpi_send(starpu_data_handle data_handle,
 	
 	MPI_Status status;
 	MPI_Datatype datatype;
-	handle_to_datatype(data_handle, &datatype);
+	starpu_mpi_handle_to_datatype(data_handle, &datatype);
 	MPI_Send(ptr, 1, datatype, dest,  mpi_tag, comm);
 
 	starpu_release_data_from_mem(data_handle);

+ 50 - 0
mpi/starpu_mpi_datatype.c

@@ -0,0 +1,50 @@
+/*
+ * 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_datatype.h>
+
+typedef int (*handle_to_datatype_func)(starpu_data_handle, MPI_Datatype *);
+
+static int handle_to_datatype_vector(starpu_data_handle data_handle, MPI_Datatype *datatype)
+{
+	unsigned nx = starpu_get_vector_nx(data_handle);
+	size_t elemsize = starpu_get_vector_elemsize(data_handle);
+
+	MPI_Type_contiguous(nx*elemsize, MPI_BYTE, datatype);
+	MPI_Type_commit(datatype);
+
+	return 0;
+}
+
+static handle_to_datatype_func handle_to_datatype_funcs[STARPU_NINTERFACES_ID] = {
+	[STARPU_BLAS_INTERFACE_ID]	= NULL,
+	[STARPU_BLOCK_INTERFACE_ID]	= NULL,
+	[STARPU_VECTOR_INTERFACE_ID]	= handle_to_datatype_vector,
+	[STARPU_CSR_INTERFACE_ID]	= NULL,
+	[STARPU_CSC_INTERFACE_ID]	= NULL,
+	[STARPU_BCSCR_INTERFACE_ID]	= NULL
+};
+
+int starpu_mpi_handle_to_datatype(starpu_data_handle data_handle, MPI_Datatype *datatype)
+{
+	unsigned id = starpu_get_handle_interface_id(data_handle);
+
+	handle_to_datatype_func func = handle_to_datatype_funcs[id];
+
+	STARPU_ASSERT(func);
+
+	return func(data_handle, datatype);
+}

+ 24 - 0
mpi/starpu_mpi_datatype.h

@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+#ifndef __STARPU_MPI_DATATYPE_H__
+#define __STARPU_MPI_DATATYPE_H__
+
+#include <starpu_mpi.h>
+
+int starpu_mpi_handle_to_datatype(starpu_data_handle data_handle, MPI_Datatype *datatype);
+
+#endif // __STARPU_MPI_DATATYPE_H__