aboutsummaryrefslogtreecommitdiff
path: root/src/Panda/c_interface.C
diff options
context:
space:
mode:
Diffstat (limited to 'src/Panda/c_interface.C')
-rw-r--r--src/Panda/c_interface.C172
1 files changed, 172 insertions, 0 deletions
diff --git a/src/Panda/c_interface.C b/src/Panda/c_interface.C
new file mode 100644
index 0000000..b6085d6
--- /dev/null
+++ b/src/Panda/c_interface.C
@@ -0,0 +1,172 @@
+/* This is a simple interface for c applications to use Panda */
+#include <stdio.h>
+#include <stdlib.h>
+#include "definitions.h"
+#include "Panda.h"
+#include "MPIFS.h"
+#include "ArrayLayout.h"
+#include "Array.h"
+
+
+extern "C" { int Panda_Create(int, int); }
+extern "C" { void Panda_Finalize(); }
+extern "C" { void PandaTimestep(struct ArrayInfo *); }
+extern "C" { void *PandaReadTimestep(struct ArrayInfo *); }
+extern "C" { void Panda_WriteAttribute(char *, char *, int, int, void *); }
+extern "C" { void *Panda_ReadAttribute(char *, char *, int *, int *); }
+extern "C" { Boolean PandaIsNewFile(char *); }
+
+typedef struct ArrayInfo {
+ char* name_; /* array name */
+ int rank_; /* rank */
+ int* size_; /* glbal size of the array */
+ int esize_; /* size of each element */
+ int mem_rank_; /* compute processor topology - rank */
+ int* mem_layout_; /* compute processor topology - mesh */
+ Distribution* mem_dist_; /* compute processor topology - dist */
+ int disk_rank_; /* io processor topology - rank */
+ int* disk_layout_; /* io processor topology - mesh */
+ Distribution* disk_dist_; /* io processor topology - dist */
+ char* data_; /* data pointer belonging to me */
+ int stencil_width_; /* stencil width */
+ struct ArrayInfo *next_; /* next element */
+} ArrayInfo;
+
+Panda *global_bear = NULL;
+extern MPIFS *MPIFS_global_obj;
+
+int Panda_Create(int ioproc_every, int is_part_time_mode)
+{
+ int i, my_app_size, my_rank, *world_ranks;
+ int io_nodes;
+
+/* if (io_nodes > 1) {
+ printf("Warning: Write Chunks instead of Write arrays.\n");
+ printf("There might be errors in Attributes write\n");
+ }*/
+
+ MPI_Comm_size(MPI_COMM_WORLD, &my_app_size);
+ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
+ world_ranks = (int *) malloc(sizeof(int)*my_app_size);
+ for (i=0; i<my_app_size; i++) world_ranks[i] = i;
+ io_nodes = (my_app_size - 1) / ioproc_every + 1;
+
+ if (is_part_time_mode) {
+ if (my_rank < io_nodes) { /* part-time io nodes */
+ global_bear = new Panda(PART_TIME_IO, my_rank, my_app_size, world_ranks,
+ my_rank, io_nodes, world_ranks);
+ //printf("##### Panda proc %d/%d PART_TIME_IO\n", my_rank, my_app_size);
+ } else { /* part-time compute nodes */
+ global_bear = new Panda(PART_TIME_COMPUTE, my_rank, my_app_size,
+ world_ranks, -1, io_nodes, world_ranks);
+ //printf("##### Panda proc %d/%d PART_TIME_COMPUTE\n", my_rank, my_app_size);
+ }
+ } else {
+// printf("Warning: Full-time I/O nodes is not integrated with Cactus yet, ");
+// printf("due to the communicator problem. Panda's part is done, though\n");
+ if (my_rank < io_nodes) { /* full-time io nodes */
+ global_bear = new Panda(IO_NODE, 0, my_rank, io_nodes, world_ranks);
+ delete global_bear;
+ free(world_ranks);
+ return 1;
+ } else { /* compute nodes */
+ for (i=0; i<(my_app_size-io_nodes); i++) world_ranks[i] += io_nodes;
+ global_bear = new Panda(COMPUTE_NODE, 1, my_rank-io_nodes,
+ my_app_size-io_nodes, world_ranks);
+ }
+ }
+ free(world_ranks);
+ return 0;
+}
+
+void Panda_Finalize()
+{
+ if (global_bear) delete global_bear;
+}
+
+
+void PandaTimestep(ArrayInfo *ptr)
+{
+/* Test if Panda_Create() has been called */
+ if (global_bear == NULL) {
+ printf("Panda object is not created yet - Use Panda_Create(...)\n");
+ return;
+ }
+
+/* Create array information */
+ ArrayLayout *mem_layout, *disk_layout;
+ Array *array;
+
+ mem_layout = new ArrayLayout(ptr->mem_rank_, ptr->mem_layout_);
+ disk_layout = new ArrayLayout(ptr->disk_rank_, ptr->disk_layout_);
+
+ array = new Array(ptr->name_, ptr->rank_, ptr->size_, ptr->esize_,
+ mem_layout, ptr->mem_dist_,
+ disk_layout, ptr->disk_dist_,
+ ptr->data_, ptr->stencil_width_);
+
+ global_bear->app_barrier();
+ printf("---------------- Panda Timestep -------------------\n");
+ //printf("name %s rank %d size %d %d %d esize %d mem_layout %d %d %d disk_layout %d stencil_width_ %d\n", ptr->name_, ptr->rank_, ptr->size_[0], ptr->size_[1], ptr->size_[2], ptr->esize_, ptr->mem_layout_[0], ptr->mem_layout_[1], ptr->mem_layout_[2], ptr->disk_layout_[0], ptr->stencil_width_);
+
+ array->timestep();
+
+ delete mem_layout;
+ delete disk_layout;
+ delete array;
+}
+
+void *PandaReadTimestep(ArrayInfo *ptr)
+{
+/* Test if Panda_Create() has been called */
+ if (global_bear == NULL) {
+ printf("Panda object is not created yet - Use Panda_Create(...)\n");
+ return NULL;
+ }
+
+/* Create array information */
+ ArrayLayout *mem_layout, *disk_layout;
+ Array *array;
+
+ mem_layout = new ArrayLayout(ptr->mem_rank_, ptr->mem_layout_);
+ disk_layout = NULL;
+ array = new Array(ptr->name_, ptr->rank_, ptr->size_, ptr->esize_,
+ mem_layout, ptr->mem_dist_,
+ disk_layout, ptr->disk_dist_,
+ ptr->data_, ptr->stencil_width_);
+
+ printf("---------------- Panda ReadTimestep -------------------\n");
+ global_bear->app_barrier();
+ array->read_timestep();
+ void *data = (void *)array->get_data_ptr();
+ array->set_data_ptr(NULL);
+
+ delete mem_layout;
+ delete array;
+ return data;
+}
+
+void Panda_WriteAttribute(char *fname, char *name, int esize,
+ int count, void *data)
+{
+ Attribute *attr = new Attribute();
+ attr->write(fname, name, esize, count, data);
+ delete attr;
+}
+
+void *Panda_ReadAttribute(char *fname, char *name, int *type, int *count)
+{
+ Attribute *attr = new Attribute();
+ attr->read(fname, name);
+ void *data = attr->get_data_ptr();
+ attr->set_data_ptr(NULL);
+ *type = attr->esize();
+ *count = attr->count();
+ delete attr;
+ return data;
+}
+
+Boolean PandaIsNewFile(char *fname)
+{
+ return MPIFS_global_obj->is_new_file(fname);
+}