|
@@ -0,0 +1,158 @@
|
|
|
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
|
|
|
+ *
|
|
|
+ * Copyright (C) 2013-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
|
|
|
+ *
|
|
|
+ * 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.
|
|
|
+ */
|
|
|
+
|
|
|
+#ifndef _STARPU_MPI_CHECKPOINT_TEMPLATE_H
|
|
|
+#define _STARPU_MPI_CHECKPOINT_TEMPLATE_H
|
|
|
+
|
|
|
+#include <starpu_mpi.h>
|
|
|
+#include <common/list.h>
|
|
|
+#include <starpu_mpi_private.h>
|
|
|
+
|
|
|
+#ifdef __cplusplus
|
|
|
+extern "C"
|
|
|
+{
|
|
|
+#endif
|
|
|
+
|
|
|
+LIST_TYPE(_starpu_mpi_checkpoint_template_item,
|
|
|
+int type;
|
|
|
+void* ptr;
|
|
|
+int count;
|
|
|
+int backup_rank;
|
|
|
+int backup_of;
|
|
|
+);
|
|
|
+
|
|
|
+struct _starpu_mpi_checkpoint_template{
|
|
|
+ struct _starpu_mpi_checkpoint_template_item_list list;
|
|
|
+ int size;
|
|
|
+ int cp_template_id;
|
|
|
+ int cp_template_current_instance;
|
|
|
+ int message_number;
|
|
|
+ int remaining_ack_awaited;
|
|
|
+ int pending;
|
|
|
+ int frozen;
|
|
|
+ starpu_pthread_mutex_t mutex;
|
|
|
+};
|
|
|
+
|
|
|
+static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_item_create(int type, void* ptr, int count, int backup_rank, int backup_of)
|
|
|
+{
|
|
|
+ struct _starpu_mpi_checkpoint_template_item* item;
|
|
|
+ _STARPU_MPI_CALLOC(item, 1, sizeof(struct _starpu_mpi_checkpoint_template_item));
|
|
|
+ item->type = type;
|
|
|
+ item->ptr = ptr;
|
|
|
+ item->count = count;
|
|
|
+ item->backup_rank = backup_rank;
|
|
|
+ item->backup_of = backup_of;
|
|
|
+
|
|
|
+ return item;
|
|
|
+}
|
|
|
+
|
|
|
+static inline starpu_mpi_checkpoint_template_t _starpu_mpi_checkpoint_template_new(int cp_id)
|
|
|
+{
|
|
|
+ starpu_mpi_checkpoint_template_t _cp_template;
|
|
|
+ _STARPU_MPI_CALLOC(_cp_template, 1, sizeof(struct _starpu_mpi_checkpoint_template));
|
|
|
+ _cp_template->cp_template_id = cp_id;
|
|
|
+ _cp_template->cp_template_current_instance = 0;
|
|
|
+ starpu_pthread_mutex_init(&_cp_template->mutex, NULL);
|
|
|
+ return _cp_template;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int _starpu_mpi_checkpoint_template_add_data(starpu_mpi_checkpoint_template_t cp_template, int type, void* ptr, int count, int backup_rank, int backup_of)
|
|
|
+{
|
|
|
+ starpu_pthread_mutex_lock(&cp_template->mutex);
|
|
|
+ STARPU_ASSERT_MSG(!cp_template->frozen, "It is not possible to modify registered checkpoint template.\n");
|
|
|
+ struct _starpu_mpi_checkpoint_template_item* item;
|
|
|
+ item = _starpu_mpi_checkpoint_template_item_create(type, ptr, count, backup_rank, backup_of);
|
|
|
+ _starpu_mpi_checkpoint_template_item_list_push_back(&cp_template->list, item);
|
|
|
+ starpu_pthread_mutex_unlock(&cp_template->mutex);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_get_first_data(starpu_mpi_checkpoint_template_t template)
|
|
|
+{
|
|
|
+ return _starpu_mpi_checkpoint_template_item_list_front(&template->list);
|
|
|
+}
|
|
|
+
|
|
|
+static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_get_next_data(starpu_mpi_checkpoint_template_t template STARPU_ATTRIBUTE_UNUSED, struct _starpu_mpi_checkpoint_template_item* ref_data)
|
|
|
+{
|
|
|
+ return _starpu_mpi_checkpoint_template_item_list_next(ref_data);
|
|
|
+}
|
|
|
+
|
|
|
+static inline struct _starpu_mpi_checkpoint_template_item* _starpu_mpi_checkpoint_template_end(starpu_mpi_checkpoint_template_t template STARPU_ATTRIBUTE_UNUSED)
|
|
|
+{
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int _starpu_mpi_checkpoint_template_freeze(starpu_mpi_checkpoint_template_t cp_template)
|
|
|
+{
|
|
|
+ starpu_pthread_mutex_lock(&cp_template->mutex);
|
|
|
+
|
|
|
+ cp_template->frozen = 1;
|
|
|
+ cp_template->message_number = 0;
|
|
|
+ cp_template->size = _starpu_mpi_checkpoint_template_item_list_size(&cp_template->list);
|
|
|
+
|
|
|
+ struct _starpu_mpi_checkpoint_template_item* item = _starpu_mpi_checkpoint_template_get_first_data(cp_template);
|
|
|
+
|
|
|
+ while (item != _starpu_mpi_checkpoint_template_end(cp_template))
|
|
|
+ {
|
|
|
+ switch (item->type)
|
|
|
+ {
|
|
|
+ case STARPU_VALUE:
|
|
|
+ cp_template->message_number++;
|
|
|
+ break;
|
|
|
+ case STARPU_R:
|
|
|
+ if (starpu_mpi_data_get_rank((starpu_data_handle_t) item->ptr))
|
|
|
+ {
|
|
|
+ cp_template->message_number++;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case STARPU_DATA_ARRAY:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ item = _starpu_mpi_checkpoint_template_get_next_data(cp_template, item);
|
|
|
+ }
|
|
|
+
|
|
|
+ starpu_pthread_mutex_unlock(&cp_template->mutex);
|
|
|
+
|
|
|
+ return cp_template->size;
|
|
|
+}
|
|
|
+
|
|
|
+static inline int _starpu_checkpoint_template_free(starpu_mpi_checkpoint_template_t cp_template)
|
|
|
+{
|
|
|
+ struct _starpu_mpi_checkpoint_template_item* item;
|
|
|
+ struct _starpu_mpi_checkpoint_template_item* next_item;
|
|
|
+ starpu_pthread_mutex_lock(&cp_template->mutex);
|
|
|
+ item = _starpu_mpi_checkpoint_template_get_first_data(cp_template);
|
|
|
+ while (item != _starpu_mpi_checkpoint_template_end(cp_template))
|
|
|
+ {
|
|
|
+ next_item = _starpu_mpi_checkpoint_template_get_next_data(cp_template, item);
|
|
|
+ starpu_free(item);
|
|
|
+ item = next_item;
|
|
|
+ }
|
|
|
+ starpu_pthread_mutex_unlock(&cp_template->mutex);
|
|
|
+ starpu_pthread_mutex_destroy(&cp_template->mutex);
|
|
|
+ starpu_free(cp_template);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+// For test purpose
|
|
|
+int _starpu_mpi_checkpoint_template_print(starpu_mpi_checkpoint_template_t cp_template);
|
|
|
+
|
|
|
+
|
|
|
+#ifdef __cplusplus
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+#endif //_STARPU_MPI_CHECKPOINT_TEMPLATE_H
|