Skip to content

Commit

Permalink
Remove the concept of readers
Browse files Browse the repository at this point in the history
  • Loading branch information
thilinarmtb committed Feb 11, 2019
1 parent d19c36d commit c637a3c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CSRCS:= $(SRCDIR)/genmap.c \
$(SRCDIR)/genmap-vector.c $(SRCDIR)/genmap-handle.c $(SRCDIR)/genmap-comm.c \
$(SRCDIR)/genmap-eigen.c $(SRCDIR)/genmap-laplacian.c $(SRCDIR)/genmap-lanczos.c \
$(SRCDIR)/genmap-rsb.c \
$(SRCDIR)/genmap-quality.c $(SRCDIR)/genmap-io.c $(SRCDIR)/genmap-chelpers.c \
$(SRCDIR)/genmap-quality.c $(SRCDIR)/genmap-chelpers.c \
$(SRCDIR)/parRSB.c
COBJS:=$(CSRCS:.c=.o)

Expand Down
17 changes: 0 additions & 17 deletions src/genmap-handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@
//
// GenmapHandle
//
int GenmapCreateHandle(GenmapHandle h) {
h->global = NULL;
h->local = NULL;

h->elementArray.ptr = NULL;
h->elementArray.n = h->elementArray.max = 0;

h->Create(h);

return 0;
}

int GenmapDestroyHandle(GenmapHandle h) {
GenmapFree(h);
return 0;
}

GenmapElements GenmapGetElements(GenmapHandle h) {
return (GenmapElements) h->elementArray.ptr;
}
Expand Down
6 changes: 2 additions & 4 deletions src/genmap-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ struct GenmapHandle_private {

struct crystal cr;

int (*Create)(GenmapHandle h);

GenmapInt dbgLevel;
GenmapInt printStat;
int dbgLevel;
int printStat;
};
//
// GenmapHandle
Expand Down
10 changes: 0 additions & 10 deletions src/genmap-io.c

This file was deleted.

73 changes: 10 additions & 63 deletions src/genmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,72 +4,20 @@
#include <stdlib.h>
#include <stdio.h>
//
// Genmap Readers (FEM meshes, .map files, etc.)
//
static struct {
char name[GENMAP_READER_LEN];
int (*Create)(GenmapHandle h);
} GenmapReaders[GENMAP_MAX_READERS];
static size_t GenmapNumReaders = 0;
static int GenmapReadersRegistered = 0;
//
// Register readers -- each reader should call this
//
int GenmapRegisterReader(char *name, int (*Create)(GenmapHandle h)) {
if(GenmapNumReaders >= sizeof(GenmapReaders) / sizeof(GenmapReaders[0])) {
//TODO: GenmapError
printf("Error: Too many readers.\n");
}

strncpy(GenmapReaders[GenmapNumReaders].name, name, GENMAP_READER_LEN);
GenmapReaders[GenmapNumReaders].Create = Create;
GenmapNumReaders++;

return 0;
}
//
// GenmapRegister
//
int GenmapRegister() {
int ierr;
ierr = GenmapRegisterReader("interface", GenmapCreateHandle_interface);
return ierr;
}
//
// GenmapInit
//
int GenmapInit(GenmapHandle *h, GenmapCommExternal ce, char *reader) {
if(GenmapReadersRegistered == 0) {
GenmapRegister();
GenmapReadersRegistered = 1;
}

char *registeredReader;
size_t matchLen = 0, matchIdx = 0;

size_t i, j;
for(i = 0; i < GenmapNumReaders; i++) {
registeredReader = GenmapReaders[i].name;
for(j = 0; reader[j]
&& (reader[j] == registeredReader[j]); j++) {
if(j > matchLen) {
matchLen = j;
matchIdx = i;
}
}
}
int GenmapInit(GenmapHandle *h, GenmapCommExternal ce) {
GenmapMalloc(1, h);
GenmapHandle h_ = *h;

if(!matchLen) {
//TODO: GenmapError
printf("Error: Reader not found.\n");
}
GenmapCreateComm(&h_->global, ce);
GenmapCreateComm(&h_->local, ce);

GenmapMalloc(1, h);
(*h)->Create = GenmapReaders[matchIdx].Create;
GenmapCreateHandle(*h);
h_->elementArray.ptr = NULL;
h_->elementArray.n = (*h)->elementArray.max = 0;

GenmapCreateComm(&(*h)->global, ce);
GenmapCreateComm(&(*h)->local, ce);
h_->dbgLevel = 0;
h_->printStat = 0;

return 0;
}
Expand All @@ -82,10 +30,9 @@ int GenmapFinalize(GenmapHandle h) {
if(GenmapGetLocalComm(h))
GenmapDestroyComm(h->local);


array_free(&(h->elementArray));

GenmapDestroyHandle(h);
GenmapFree(h);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/genmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct GenmapElement_private *GenmapElements;
//
// Genmap: Init, Finalize
//
int GenmapInit(GenmapHandle *h, GenmapCommExternal ce, char *reader);
int GenmapInit(GenmapHandle *h, GenmapCommExternal ce);
int GenmapFinalize(GenmapHandle h);
//
// GenmapMalloc, Realloc, Calloc and Free
Expand Down
2 changes: 1 addition & 1 deletion src/parRSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ int parRSB_partMesh(long long *egl, long long *vl, int *negl,
long long *eglcon, long long *vlcon, int neglcon,
int nve, int *options, MPI_Comm comm) {
GenmapHandle h;
GenmapInit(&h, comm, "interface");
GenmapInit(&h, comm);

if(options[0] != 0) {
h->dbgLevel = options[1];
Expand Down

0 comments on commit c637a3c

Please sign in to comment.