Browse Source

mpi/examples/user_datatype: fix code, there is no need to use a static variable to compute the mpi datatype

Nathalie Furmento 7 years ago
parent
commit
e51f18fe73

+ 3 - 4
mpi/examples/user_datatype/my_interface.c

@@ -44,15 +44,13 @@ void starpu_my_interface_compare_codelet_cpu(void *descr[], void *_args)
 	*compare = (d0 == d1 && c0 == c1);
 }
 
-static struct starpu_my_interface *myinterface = NULL;
-
 void _starpu_my_interface_datatype_allocate(MPI_Datatype *mpi_datatype)
 {
 	int ret;
-
 	int blocklengths[2] = {1, 1};
 	MPI_Aint displacements[2];
 	MPI_Datatype types[2] = {MPI_INT, MPI_CHAR};
+	struct starpu_my_interface *myinterface = NULL;
 	myinterface = malloc(sizeof(struct starpu_my_interface));
 
 	MPI_Address(myinterface, displacements);
@@ -65,6 +63,8 @@ void _starpu_my_interface_datatype_allocate(MPI_Datatype *mpi_datatype)
 
 	ret = MPI_Type_commit(mpi_datatype);
 	STARPU_ASSERT_MSG(ret == MPI_SUCCESS, "MPI_Type_commit failed");
+
+	free(myinterface);
 }
 
 void starpu_my_interface_datatype_allocate(starpu_data_handle_t handle, MPI_Datatype *mpi_datatype)
@@ -76,7 +76,6 @@ void starpu_my_interface_datatype_allocate(starpu_data_handle_t handle, MPI_Data
 void starpu_my_interface_datatype_free(MPI_Datatype *mpi_datatype)
 {
 	MPI_Type_free(mpi_datatype);
-	free(myinterface);
 }
 
 int starpu_my_interface_get_int(starpu_data_handle_t handle)

+ 5 - 0
mpi/examples/user_datatype/user_datatype.c

@@ -109,5 +109,10 @@ int main(int argc, char **argv)
 	starpu_mpi_shutdown();
 	starpu_shutdown();
 
+	if (rank == 0)
+	{
+		FPRINTF(stderr, "[node 0] %s\n", compare==1?"SUCCESS":"FAILURE");
+	}
+
 	return (rank == 0) ? !compare : 0;
 }