diff --git a/qse/cmd/awk/Makefile.am b/qse/cmd/awk/Makefile.am index 5cb7ac3f..7883f98b 100644 --- a/qse/cmd/awk/Makefile.am +++ b/qse/cmd/awk/Makefile.am @@ -19,20 +19,3 @@ qseawk_LDADD += $(UNICOWS_LIBS) endif endif -#####################################################################3 - -if HAVE_C_MPI -bin_PROGRAMS += qseawkmp - -qseawkmp_SOURCES = mpi.c -qseawkmp_CPPFLAGS = $(AM_CPPFLAGS) $(MPI_CFLAGS) -qseawkmp_LDFLAGS = -L../../lib/awk -L../../lib/cmn -L$(libdir) $(MPI_CLDFLAGS) -qseawkmp_LDADD = -lqseawkmp -lqseawk -lqsecmn $(LIBM) - -if WIN32 -if WCHAR -qseawkmp_LDADD += $(UNICOWS_LIBS) -endif -endif - -endif diff --git a/qse/cmd/awk/Makefile.in b/qse/cmd/awk/Makefile.in index db4aa71b..fd2fa026 100644 --- a/qse/cmd/awk/Makefile.in +++ b/qse/cmd/awk/Makefile.in @@ -34,12 +34,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = qseawk$(EXEEXT) $(am__EXEEXT_1) +bin_PROGRAMS = qseawk$(EXEEXT) @WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS) - -#####################################################################3 -@HAVE_C_MPI_TRUE@am__append_2 = qseawkmp -@HAVE_C_MPI_TRUE@@WCHAR_TRUE@@WIN32_TRUE@am__append_3 = $(UNICOWS_LIBS) subdir = cmd/awk DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -55,7 +51,6 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/include/qse/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = -@HAVE_C_MPI_TRUE@am__EXEEXT_1 = qseawkmp$(EXEEXT) am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) am_qseawk_OBJECTS = awk.$(OBJEXT) @@ -66,15 +61,6 @@ qseawk_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) qseawk_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(qseawk_LDFLAGS) \ $(LDFLAGS) -o $@ -am__qseawkmp_SOURCES_DIST = mpi.c -@HAVE_C_MPI_TRUE@am_qseawkmp_OBJECTS = qseawkmp-mpi.$(OBJEXT) -qseawkmp_OBJECTS = $(am_qseawkmp_OBJECTS) -@HAVE_C_MPI_TRUE@@WCHAR_TRUE@@WIN32_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1) -@HAVE_C_MPI_TRUE@qseawkmp_DEPENDENCIES = $(am__DEPENDENCIES_1) \ -@HAVE_C_MPI_TRUE@ $(am__DEPENDENCIES_3) -qseawkmp_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(qseawkmp_LDFLAGS) \ - $(LDFLAGS) -o $@ DEFAULT_INCLUDES = depcomp = $(SHELL) $(top_srcdir)/ac/depcomp am__depfiles_maybe = depfiles @@ -88,8 +74,8 @@ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = $(qseawk_SOURCES) $(qseawkmp_SOURCES) -DIST_SOURCES = $(qseawk_SOURCES) $(am__qseawkmp_SOURCES_DIST) +SOURCES = $(qseawk_SOURCES) +DIST_SOURCES = $(qseawk_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -273,11 +259,6 @@ AM_CPPFLAGS = \ qseawk_SOURCES = awk.c qseawk_LDFLAGS = -L../../lib/awk -L../../lib/cmn -L$(libdir) qseawk_LDADD = -lqseawk -lqsecmn $(LIBM) $(am__append_1) -@HAVE_C_MPI_TRUE@qseawkmp_SOURCES = mpi.c -@HAVE_C_MPI_TRUE@qseawkmp_CPPFLAGS = $(AM_CPPFLAGS) $(MPI_CFLAGS) -@HAVE_C_MPI_TRUE@qseawkmp_LDFLAGS = -L../../lib/awk -L../../lib/cmn -L$(libdir) $(MPI_CLDFLAGS) -@HAVE_C_MPI_TRUE@qseawkmp_LDADD = -lqseawkmp -lqseawk -lqsecmn $(LIBM) \ -@HAVE_C_MPI_TRUE@ $(am__append_3) all: all-am .SUFFIXES: @@ -358,9 +339,6 @@ clean-binPROGRAMS: qseawk$(EXEEXT): $(qseawk_OBJECTS) $(qseawk_DEPENDENCIES) $(EXTRA_qseawk_DEPENDENCIES) @rm -f qseawk$(EXEEXT) $(qseawk_LINK) $(qseawk_OBJECTS) $(qseawk_LDADD) $(LIBS) -qseawkmp$(EXEEXT): $(qseawkmp_OBJECTS) $(qseawkmp_DEPENDENCIES) $(EXTRA_qseawkmp_DEPENDENCIES) - @rm -f qseawkmp$(EXEEXT) - $(qseawkmp_LINK) $(qseawkmp_OBJECTS) $(qseawkmp_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -369,7 +347,6 @@ distclean-compile: -rm -f *.tab.c @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/awk.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qseawkmp-mpi.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -392,20 +369,6 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< -qseawkmp-mpi.o: mpi.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(qseawkmp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT qseawkmp-mpi.o -MD -MP -MF $(DEPDIR)/qseawkmp-mpi.Tpo -c -o qseawkmp-mpi.o `test -f 'mpi.c' || echo '$(srcdir)/'`mpi.c -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/qseawkmp-mpi.Tpo $(DEPDIR)/qseawkmp-mpi.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mpi.c' object='qseawkmp-mpi.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(qseawkmp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o qseawkmp-mpi.o `test -f 'mpi.c' || echo '$(srcdir)/'`mpi.c - -qseawkmp-mpi.obj: mpi.c -@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(qseawkmp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT qseawkmp-mpi.obj -MD -MP -MF $(DEPDIR)/qseawkmp-mpi.Tpo -c -o qseawkmp-mpi.obj `if test -f 'mpi.c'; then $(CYGPATH_W) 'mpi.c'; else $(CYGPATH_W) '$(srcdir)/mpi.c'; fi` -@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/qseawkmp-mpi.Tpo $(DEPDIR)/qseawkmp-mpi.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mpi.c' object='qseawkmp-mpi.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(qseawkmp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o qseawkmp-mpi.obj `if test -f 'mpi.c'; then $(CYGPATH_W) 'mpi.c'; else $(CYGPATH_W) '$(srcdir)/mpi.c'; fi` - mostlyclean-libtool: -rm -f *.lo diff --git a/qse/cmd/awk/awk.c b/qse/cmd/awk/awk.c index 16c6cc56..40d9895f 100644 --- a/qse/cmd/awk/awk.c +++ b/qse/cmd/awk/awk.c @@ -58,10 +58,6 @@ # define USE_LTDL #endif -#if defined(ENABLE_MPI) -# include -#endif - static qse_awk_rtx_t* app_rtx = QSE_NULL; static int app_debug = 0; @@ -1166,20 +1162,6 @@ int qse_main (int argc, qse_achar_t* argv[]) qse_setdflcmgrbyid (QSE_CMGR_SLMB); #endif -#if defined(ENABLE_MPI) - /* I didn't manage to find a good way to change the - * default error handler to MPI_ERRORS_RETURN. - * so MPI_Init() will simply abort the program if it fails */ - if (MPI_Init (&argc, &argv) != MPI_SUCCESS) - { - print_error (QSE_T("Failed to initialize MPI\n")); - ret = -1; - goto oops; - } - - MPI_Comm_set_errhandler (MPI_COMM_WORLD, MPI_ERRORS_RETURN); -#endif - #if defined(USE_LTDL) lt_dlinit (); #endif @@ -1190,11 +1172,6 @@ int qse_main (int argc, qse_achar_t* argv[]) lt_dlexit (); #endif -#if defined(ENABLE_MPI) - MPI_Finalize (); -oops: -#endif - #if defined(_WIN32) WSACleanup (); #endif diff --git a/qse/cmd/awk/mpi.c b/qse/cmd/awk/mpi.c deleted file mode 100644 index 253a73d1..00000000 --- a/qse/cmd/awk/mpi.c +++ /dev/null @@ -1,14 +0,0 @@ - - -#define ENABLE_MPI - -#define qse_awk_openstd qse_awk_openmpi -#define qse_awk_openstdwithmmgr qse_awk_openmpiwithmmgr -#define qse_awk_getxtnstd qse_awk_getxtnmpi -#define qse_awk_parsestd qse_awk_parsempi -#define qse_awk_rtx_openstd qse_awk_rtx_openmpi -#define qse_awk_rtx_getxtnstd qse_awk_rtx_getxtnmpi -#define qse_awk_rtx_getcmgrstd qse_awk_rtx_getcmgrmpi - -#include "awk.c" - diff --git a/qse/include/qse/awk/Awk.hpp b/qse/include/qse/awk/Awk.hpp index e5e1a416..05486383 100644 --- a/qse/include/qse/awk/Awk.hpp +++ b/qse/include/qse/awk/Awk.hpp @@ -1224,6 +1224,10 @@ protected: virtual flt_t exp (flt_t x) = 0; virtual flt_t sqrt (flt_t x) = 0; + virtual void* modopen (const char_t* dir, const char_t* name) = 0; + virtual void modclose (void* handle) = 0; + virtual void* modsym (void* handle, const char_t* name) = 0; + // static glue members for various handlers static ssize_t readSource ( awk_t* awk, sio_cmd_t cmd, sio_arg_t* arg, @@ -1245,19 +1249,23 @@ protected: static int functionHandler (rtx_t* rtx, const fnc_info_t* fi); - static int sprintf (awk_t* data, char_t* buf, size_t size, + static int sprintf (awk_t* awk, char_t* buf, size_t size, const char_t* fmt, ...); - static flt_t pow (awk_t* data, flt_t x, flt_t y); - static flt_t mod (awk_t* data, flt_t x, flt_t y); - static flt_t sin (awk_t* data, flt_t x); - static flt_t cos (awk_t* data, flt_t x); - static flt_t tan (awk_t* data, flt_t x); - static flt_t atan (awk_t* data, flt_t x); - static flt_t atan2 (awk_t* data, flt_t x, flt_t y); - static flt_t log (awk_t* data, flt_t x); - static flt_t log10 (awk_t* data, flt_t x); - static flt_t exp (awk_t* data, flt_t x); - static flt_t sqrt (awk_t* data, flt_t x); + static flt_t pow (awk_t* awk, flt_t x, flt_t y); + static flt_t mod (awk_t* awk, flt_t x, flt_t y); + static flt_t sin (awk_t* awk, flt_t x); + static flt_t cos (awk_t* awk, flt_t x); + static flt_t tan (awk_t* awk, flt_t x); + static flt_t atan (awk_t* awk, flt_t x); + static flt_t atan2 (awk_t* awk, flt_t x, flt_t y); + static flt_t log (awk_t* awk, flt_t x); + static flt_t log10 (awk_t* awk, flt_t x); + static flt_t exp (awk_t* awk, flt_t x); + static flt_t sqrt (awk_t* awk, flt_t x); + + static void* modopen (awk_t* awk, const char_t* dir, const char_t* name); + static void modclose (awk_t* awk, void* handle); + static void* modsym (awk_t* awk, void* handle, const char_t* name); protected: awk_t* awk; diff --git a/qse/include/qse/awk/StdAwk.hpp b/qse/include/qse/awk/StdAwk.hpp index 00a86ba2..283307dc 100644 --- a/qse/include/qse/awk/StdAwk.hpp +++ b/qse/include/qse/awk/StdAwk.hpp @@ -200,6 +200,10 @@ protected: flt_t exp (flt_t x); flt_t sqrt (flt_t x); + void* modopen (const char_t* dir, const char_t* name); + void modclose (void* handle); + void* modsym (void* handle, const char_t* name); + protected: qse_long_t seed; qse_ulong_t prand; diff --git a/qse/lib/awk/Awk.cpp b/qse/lib/awk/Awk.cpp index e972cb95..11753976 100644 --- a/qse/lib/awk/Awk.cpp +++ b/qse/lib/awk/Awk.cpp @@ -1093,6 +1093,9 @@ int Awk::open () prm.math.log10 = log10; prm.math.exp = exp; prm.math.sqrt = sqrt; + prm.modopen = modopen; + prm.modclose = modclose; + prm.modsym = modsym; awk = qse_awk_open (this->getMmgr(), QSE_SIZEOF(xtn_t), &prm); if (awk == QSE_NULL) @@ -2009,6 +2012,23 @@ Awk::flt_t Awk::sqrt (awk_t* awk, flt_t x) return xtn->awk->sqrt (x); } +void* Awk::modopen (awk_t* awk, const char_t* dir, const char_t* name) +{ + xtn_t* xtn = (xtn_t*) QSE_XTN (awk); + return xtn->awk->modopen (dir, name); +} + +void Awk::modclose (awk_t* awk, void* handle) +{ + xtn_t* xtn = (xtn_t*) QSE_XTN (awk); + xtn->awk->modclose (handle); +} + +void* Awk::modsym (awk_t* awk, void* handle, const char_t* name) +{ + xtn_t* xtn = (xtn_t*) QSE_XTN (awk); + return xtn->awk->modsym (handle, name); +} ///////////////////////////////// QSE_END_NAMESPACE(QSE) ///////////////////////////////// diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index 47056f3f..98eeaec2 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -44,6 +44,7 @@ /* anything ? */ #else # include +# include #endif #ifndef QSE_HAVE_CONFIG_H @@ -1381,6 +1382,106 @@ StdAwk::flt_t StdAwk::sqrt (flt_t x) #endif } +void* StdAwk::modopen (const qse_char_t* dir, const qse_char_t* name) +{ +#if defined(_WIN32) + /*TODO: implemente this - use LoadLibrary... */ + this->setError (QSE_AWK_ENOIMPL); + return -1; +#elif defined(__OS2__) + /*TODO: implemente this */ + this->setError (QSE_AWK_ENOIMPL); + return -1; +#elif defined(__DOS__) + /*TODO: implemente this */ + this->setError (QSE_AWK_ENOIMPL); + return -1; +#else + + void* h; + qse_mchar_t* modpath; + const qse_char_t* tmp[5]; + int count = 0; + + if (dir && dir[0] != QSE_T('\0')) + { + tmp[count++] = dir; + tmp[count++] = QSE_T("/"); + } + tmp[count++] = QSE_T("libawk"); + tmp[count++] = name; + tmp[count] = QSE_NULL; + + #if defined(QSE_CHAR_IS_MCHAR) + modpath = qse_mbsadup (tmp, QSE_NULL, this->getMmgr()); + #else + modpath = qse_wcsatombsdup (tmp, QSE_NULL, this->getMmgr()); + #endif + if (!modpath) + { + this->setError (QSE_AWK_ENOMEM); + return QSE_NULL; + } + + h = lt_dlopenext (modpath); + + QSE_MMGR_FREE (awk->mmgr, modpath); + + return h; + +#endif +} + +void StdAwk::modclose (void* handle) +{ +#if defined(_WIN32) + /*TODO: implemente this */ +#elif defined(__OS2__) + /*TODO: implemente this */ +#elif defined(__DOS__) + /*TODO: implemente this */ +#else + lt_dlclose ((lt_dlhandle)handle); +#endif +} + +void* StdAwk::modsym (void* handle, const qse_char_t* name) +{ +#if defined(_WIN32) + /*TODO: implemente this */ +#elif defined(__OS2__) + /*TODO: implemente this */ +#elif defined(__DOS__) + /*TODO: implemente this */ +#else + + void* s; + qse_mchar_t* mname; + + #if defined(QSE_CHAR_IS_MCHAR) + mname = name; + #else + mname = qse_wcstombsdup (name, QSE_NULL, this->getMmgr()); + if (!mname) + { + this->setError (QSE_AWK_ENOMEM); + return QSE_NULL; + } + #endif + + s = lt_dlsym ((lt_dlhandle)handle, mname); + + #if defined(QSE_CHAR_IS_MCHAR) + /* nothing to do */ + #else + QSE_MMGR_FREE (awk->mmgr, mname); + #endif + + return s; + +#endif +} + int StdAwk::SourceFile::open (Data& io) { qse_sio_t* sio; diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index f2c518ee..aee949fc 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -345,6 +345,11 @@ static void* custom_awk_modopen ( #else modpath = qse_wcsatombsdup (tmp, QSE_NULL, awk->mmgr); #endif + if (!modpath) + { + qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); + return QSE_NULL; + } h = lt_dlopenext (modpath); @@ -2539,136 +2544,3 @@ static int add_functions (qse_awk_t* awk) return 0; } -#if 0 - -static int query_module ( - qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) -{ - const qse_char_t* dc; - xtn_t* xtn; - qse_rbt_pair_t* pair; - qse_size_t namelen; - mod_data_t md; - qse_cstr_t ea; - - xtn = (xtn_t*)QSE_XTN(awk); - - /* TODO: support module calls with deeper levels ... */ - dc = qse_strstr (name, QSE_T("::")); - QSE_ASSERT (dc != QSE_NULL); - - namelen = dc - name; - -#if defined(_WIN32) - /*TODO: implemente this */ - qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL); - return -1; -#elif defined(__OS2__) - /*TODO: implemente this */ - qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL); - return -1; -#elif defined(__DOS__) - qse_awk_seterrnum (awk, QSE_AWK_ENOIMPL, QSE_NULL); - return -1; -#else - - pair = qse_rbt_search (&xtn->modtab, name, namelen); - if (pair) - { - md = *(mod_data_t*)QSE_RBT_VPTR(pair); - } - else - { - qse_mchar_t* modpath; - qse_awk_modstd_load_t load; - - #if defined(QSE_CHAR_IS_MCHAR) - qse_mcstr_t tmp[5] = - { - { QSE_WT(""), 0 }, - { QSE_WT("/"), 0 }, - { QSE_MT("lib"), 3 }, - { QSE_NULL, 0 }, - { QSE_NULL, 0 } - }; - #else - qse_wcstr_t tmp[5] = - { - { QSE_WT(""), 0 }, - { QSE_WT("/"), 0 }, - { QSE_WT("lib"), 3 }, - { QSE_NULL, 0 }, - { QSE_NULL, 0 } - }; - #endif - - if (xtn->opt.moddir.len > 0) - { - tmp[0].ptr = xtn->opt.moddir.ptr; - tmp[0].len = xtn->opt.moddir.len; - tmp[1].len = 1; - } - #if defined(DEFAULT_MODDIR) - else - { - tmp[0].ptr = QSE_T(DEFAULT_MODDIR); - tmp[0].len = qse_strlen(tmp[0].ptr); - tmp[1].len = 1; - } - #endif - - tmp[3].ptr = name; - tmp[3].len = namelen; - - #if defined(QSE_CHAR_IS_MCHAR) - modpath = qse_mcstradup (tmp, QSE_NULL, awk->mmgr); - #else - modpath = qse_wcsnatombsdup (tmp, QSE_NULL, awk->mmgr); - #endif - if (!modpath) - { - qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); - return -1; - } - - md.dh = lt_dlopenext (modpath); - QSE_MMGR_FREE (awk->mmgr, modpath); - if (!md.dh) - { - ea.ptr = name; - ea.len = namelen; - qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL); - return -1; - } - - load = lt_dlsym (md.dh, QSE_MT("load")); - if (!load) - { - lt_dlclose (md.dh); - - ea.ptr = QSE_T("load"); - ea.len = 4; - qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL); - return -1; - } - - if (load (&md.modstd, awk) <= -1) - { - lt_dlclose (md.dh); - return -1; - } - - if (qse_rbt_insert (&xtn->modtab, (void*)name, namelen, &md, QSE_SIZEOF(md)) == QSE_NULL) - { - qse_awk_seterrnum (awk, QSE_AWK_ENOMEM, QSE_NULL); - lt_dlclose (md.dh); - return -1; - } - } - - return md.modstd.query (&md.modstd, awk, dc + 2, sym); -#endif -} - - -#endif diff --git a/qse/mod/awk/Makefile.am b/qse/mod/awk/Makefile.am index 558f0bf6..85d244d6 100644 --- a/qse/mod/awk/Makefile.am +++ b/qse/mod/awk/Makefile.am @@ -13,10 +13,17 @@ libawksys_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../l libawksys_la_LIBADD = -lqseawk -lqsecmn if HAVE_LIBUCI - mod_LTLIBRARIES += libawkuci.la libawkuci_la_SOURCES = uci.c libawkuci_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined libawkuci_la_LIBADD = -lqseawk -lqsecmn $(UCI_LIBS) - +endif + + +if HAVE_C_MPI +mod_LTLIBRARIES += libawkmpi.la +libawkmpi_la_CPPFLAGS = $(AM_CPPFLAGS) $(MPI_CFLAGS) +libawkmpi_la_SOURCES = mpi.c +libawkmpi_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined $(MPI_CLDFLAGS) +libawkmpi_la_LIBADD = -lqseawk -lqsecmn endif diff --git a/qse/mod/awk/Makefile.in b/qse/mod/awk/Makefile.in index 7ba13eea..cefc7475 100644 --- a/qse/mod/awk/Makefile.in +++ b/qse/mod/awk/Makefile.in @@ -35,6 +35,7 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ @HAVE_LIBUCI_TRUE@am__append_1 = libawkuci.la +@HAVE_C_MPI_TRUE@am__append_2 = libawkmpi.la subdir = mod/awk DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -79,6 +80,14 @@ am__uninstall_files_from_dir = { \ } am__installdirs = "$(DESTDIR)$(moddir)" LTLIBRARIES = $(mod_LTLIBRARIES) +libawkmpi_la_DEPENDENCIES = +am__libawkmpi_la_SOURCES_DIST = mpi.c +@HAVE_C_MPI_TRUE@am_libawkmpi_la_OBJECTS = libawkmpi_la-mpi.lo +libawkmpi_la_OBJECTS = $(am_libawkmpi_la_OBJECTS) +libawkmpi_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(libawkmpi_la_LDFLAGS) $(LDFLAGS) -o $@ +@HAVE_C_MPI_TRUE@am_libawkmpi_la_rpath = -rpath $(moddir) libawksys_la_DEPENDENCIES = am_libawksys_la_OBJECTS = sys.lo libawksys_la_OBJECTS = $(am_libawksys_la_OBJECTS) @@ -107,9 +116,10 @@ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ -SOURCES = $(libawksys_la_SOURCES) $(libawkuci_la_SOURCES) -DIST_SOURCES = $(libawksys_la_SOURCES) \ - $(am__libawkuci_la_SOURCES_DIST) +SOURCES = $(libawkmpi_la_SOURCES) $(libawksys_la_SOURCES) \ + $(libawkuci_la_SOURCES) +DIST_SOURCES = $(am__libawkmpi_la_SOURCES_DIST) \ + $(libawksys_la_SOURCES) $(am__libawkuci_la_SOURCES_DIST) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -291,13 +301,17 @@ AM_CPPFLAGS = \ -I$(includedir) moddir = $(libdir)/qse -mod_LTLIBRARIES = libawksys.la $(am__append_1) +mod_LTLIBRARIES = libawksys.la $(am__append_1) $(am__append_2) libawksys_la_SOURCES = sys.c libawksys_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined libawksys_la_LIBADD = -lqseawk -lqsecmn @HAVE_LIBUCI_TRUE@libawkuci_la_SOURCES = uci.c @HAVE_LIBUCI_TRUE@libawkuci_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined @HAVE_LIBUCI_TRUE@libawkuci_la_LIBADD = -lqseawk -lqsecmn $(UCI_LIBS) +@HAVE_C_MPI_TRUE@libawkmpi_la_CPPFLAGS = $(AM_CPPFLAGS) $(MPI_CFLAGS) +@HAVE_C_MPI_TRUE@libawkmpi_la_SOURCES = mpi.c +@HAVE_C_MPI_TRUE@libawkmpi_la_LDFLAGS = -L$(abs_builddir)/../../lib/cmn -L$(abs_builddir)/../../lib/awk -L$(libdir) -version-info 1:0:0 -no-undefined $(MPI_CLDFLAGS) +@HAVE_C_MPI_TRUE@libawkmpi_la_LIBADD = -lqseawk -lqsecmn all: all-am .SUFFIXES: @@ -363,6 +377,8 @@ clean-modLTLIBRARIES: echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done +libawkmpi.la: $(libawkmpi_la_OBJECTS) $(libawkmpi_la_DEPENDENCIES) $(EXTRA_libawkmpi_la_DEPENDENCIES) + $(libawkmpi_la_LINK) $(am_libawkmpi_la_rpath) $(libawkmpi_la_OBJECTS) $(libawkmpi_la_LIBADD) $(LIBS) libawksys.la: $(libawksys_la_OBJECTS) $(libawksys_la_DEPENDENCIES) $(EXTRA_libawksys_la_DEPENDENCIES) $(libawksys_la_LINK) -rpath $(moddir) $(libawksys_la_OBJECTS) $(libawksys_la_LIBADD) $(LIBS) libawkuci.la: $(libawkuci_la_OBJECTS) $(libawkuci_la_DEPENDENCIES) $(EXTRA_libawkuci_la_DEPENDENCIES) @@ -374,6 +390,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libawkmpi_la-mpi.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sys.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uci.Plo@am__quote@ @@ -398,6 +415,13 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< +libawkmpi_la-mpi.lo: mpi.c +@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libawkmpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libawkmpi_la-mpi.lo -MD -MP -MF $(DEPDIR)/libawkmpi_la-mpi.Tpo -c -o libawkmpi_la-mpi.lo `test -f 'mpi.c' || echo '$(srcdir)/'`mpi.c +@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/libawkmpi_la-mpi.Tpo $(DEPDIR)/libawkmpi_la-mpi.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='mpi.c' object='libawkmpi_la-mpi.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libawkmpi_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libawkmpi_la-mpi.lo `test -f 'mpi.c' || echo '$(srcdir)/'`mpi.c + mostlyclean-libtool: -rm -f *.lo diff --git a/qse/mod/awk/mpi.c b/qse/mod/awk/mpi.c new file mode 100644 index 00000000..6f92afe6 --- /dev/null +++ b/qse/mod/awk/mpi.c @@ -0,0 +1,248 @@ +#include +#include + +#include + +static int fnc_hash (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + qse_awk_val_t* retv; + qse_long_t hv; + + hv = qse_awk_rtx_hashval (rtx, qse_awk_rtx_getarg (rtx, 0)); + + retv = qse_awk_rtx_makeintval (rtx, hv); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + +static int fnc_assign (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + qse_awk_val_t* retv; + qse_long_t limit; + int rx; + + rx = qse_awk_rtx_valtolong (rtx, qse_awk_rtx_getarg (rtx, 0), &limit); + if (rx >= 0) + { + qse_awk_nrflt_t nrflt; + + nrflt.limit = limit; +// nrflt.size = rxtn->size; +// nrflt.rank = rxtn->rank; + qse_awk_rtx_setnrflt (rtx, &nrflt); + } + + retv = qse_awk_rtx_makeintval (rtx, rx); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + +#if 0 +static int fnc_reduce (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + qse_size_t nargs; + qse_awk_val_t* tmp, * a0, * a1; + qse_long_t opidx, lv; + qse_flt_t rv; + int n; + rxtn_t* rxtn; + + static MPI_Op optab[] = + { + MPI_MIN, + MPI_MAX, + MPI_SUM, + MPI_PROD, + MPI_LAND, + MPI_LOR + }; + + rxtn = (rxtn_t*) qse_awk_rtx_getxtnstd (rtx); + + nargs = qse_awk_rtx_getnargs (rtx); + QSE_ASSERT (nargs == 2); + + a0 = qse_awk_rtx_getarg (rtx, 0); + a1 = qse_awk_rtx_getarg (rtx, 1); + + if (qse_awk_rtx_valtolong (rtx, a1, &opidx) <= -1) return -1; + if (opidx < 0 || opidx >= QSE_COUNTOF(optab)) goto softfail; + if ((n = qse_awk_rtx_valtonum (rtx, a0, &lv, &rv)) <= -1) return -1; + +/* TODO: determine it to be MPI_LONG or MPI_INT, OR MPI_LONG_LONG_INT depending on the size of qse_long_t */ +/* TODO: how to tell normal -1 from the soft failure??? */ + if (n == 0) + { + qse_long_t lout; + if (MPI_Allreduce (&lv, &lout, 1, MPI_LONG_LONG_INT, optab[opidx], rxtn->comm) != MPI_SUCCESS) goto softfail; + tmp = qse_awk_rtx_makeintval (rtx, lout); + } + else + { + qse_flt_t fout; + if (MPI_Allreduce (&rv, &fout, 1, MPI_LONG_DOUBLE, optab[opidx], rxtn->comm) != MPI_SUCCESS) goto softfail; + tmp = qse_awk_rtx_makefltval (rtx, fout); + } + + if (tmp == QSE_NULL) return -1; + qse_awk_rtx_setretval (rtx, tmp); + + return 0; + +softfail: + tmp = qse_awk_rtx_makeintval (rtx, (qse_long_t)-1); + if (tmp == QSE_NULL) return -1; + qse_awk_rtx_setretval (rtx, tmp); + return 0; +} +#endif + +static int fnc_barrier (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + int rx; + qse_awk_val_t* retv; +// rxtn_t* rxtn; + +// rxtn = (rxtn_t*) qse_awk_rtx_getxtnstd (rtx); + +// x = (MPI_Barrier (rxtn->comm) == MPI_SUCCESS)? 0: -1; + rx = (MPI_Barrier (MPI_COMM_WORLD) == MPI_SUCCESS)? 0: -1; + + retv = qse_awk_rtx_makeintval (rtx, rx); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + +static int fnc_init (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + int rx; + qse_awk_val_t* retv; + + /* I didn't manage to find a good way to change the + * default error handler to MPI_ERRORS_RETURN. + * so MPI_Init() will simply abort the program if it fails */ +// if (MPI_Init (&argc, &argv) != MPI_SUCCESS) rx = -1; +// else +// { + MPI_Comm_set_errhandler (MPI_COMM_WORLD, MPI_ERRORS_RETURN); + rx = 0; +// } + + retv = qse_awk_rtx_makeintval (rtx, rx); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + +static int fnc_fini (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + int rx; + qse_awk_val_t* retv; + + MPI_Finalize (); + rx = 0; + + retv = qse_awk_rtx_makeintval (rtx, rx); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + +/* ------------------------------------------------------------------------- */ + +typedef struct fnctab_t fnctab_t; +struct fnctab_t +{ + const qse_char_t* name; + qse_awk_mod_sym_fnc_t info; +}; + +typedef struct inttab_t inttab_t; +struct inttab_t +{ + const qse_char_t* name; + qse_awk_mod_sym_int_t info; +}; + +static fnctab_t fnctab[] = +{ + { QSE_T("assign"), { { 1, 1 }, fnc_assign } }, + { QSE_T("barrier"), { { 0, 0 }, fnc_barrier } }, + { QSE_T("fini"), { { 0, 0 }, fnc_fini } }, + { QSE_T("hash"), { { 1, 1 }, fnc_hash } }, + { QSE_T("init"), { { 0, 0 }, fnc_init } } +}; + +static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qse_awk_mod_sym_t* sym) +{ + qse_cstr_t ea; + int i; + +/* TODO: binary search or something better */ + for (i = 0; i < QSE_COUNTOF(fnctab); i++) + { + if (qse_strcmp (fnctab[i].name, name) == 0) + { + sym->type = QSE_AWK_MOD_FNC; + sym->u.fnc = fnctab[i].info; + return 0; + } + } + +#if 0 + for (i = 0; i < QSE_COUNTOF(inttab); i++) + { + if (qse_strcmp (inttab[i].name, name) == 0) + { + sym->type = QSE_AWK_MOD_INT; + sym->u.in = inttab[i].info; + return 0; + } + } +#endif + + ea.ptr = name; + ea.len = qse_strlen(name); + qse_awk_seterror (awk, QSE_AWK_ENOENT, &ea, QSE_NULL); + return -1; +} + +/* TODO: proper resource management */ + +int init (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx) +{ + return 0; +} + +void fini (qse_awk_mod_t* mod, qse_awk_rtx_t* rtx) +{ + /* TODO: anything */ +} + +static void unload (qse_awk_mod_t* mod, qse_awk_t* awk) +{ + /* TODO: anything */ +} + +int load (qse_awk_mod_t* mod, qse_awk_t* awk) +{ + mod->query = query; + mod->unload = unload; + + mod->init = init; + mod->fini = fini; + /* + mod->ctx... + */ + + return 0; +} + diff --git a/qse/mod/awk/sys.c b/qse/mod/awk/sys.c index 525ecd53..485a9811 100644 --- a/qse/mod/awk/sys.c +++ b/qse/mod/awk/sys.c @@ -46,6 +46,34 @@ static int fnc_fork (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) return 0; } +static int fnc_getpid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + qse_long_t pid; + qse_awk_val_t* retv; + +#if defined(_WIN32) + /* TOOD: implement this*/ + pid = -1; + +#elif defined(__OS2__) + /* TOOD: implement this*/ + pid = -1; + +#elif defined(__DOS__) + /* TOOD: implement this*/ + pid = -1; + +#else + pid = getpid (); +#endif + + retv = qse_awk_rtx_makeintval (rtx, pid); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { qse_long_t pid; @@ -78,6 +106,35 @@ static int fnc_wait (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) return 0; } +static int fnc_getppid (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) +{ + qse_long_t pid; + qse_awk_val_t* retv; + +#if defined(_WIN32) + /* TOOD: implement this*/ + pid = -1; + +#elif defined(__OS2__) + /* TOOD: implement this*/ + pid = -1; + +#elif defined(__DOS__) + /* TOOD: implement this*/ + pid = -1; + +#else + pid = getppid (); +#endif + + retv = qse_awk_rtx_makeintval (rtx, pid); + if (retv == QSE_NULL) return -1; + + qse_awk_rtx_setretval (rtx, retv); + return 0; +} + + static int fnc_kill (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) { qse_long_t pid, sig; @@ -159,6 +216,8 @@ struct inttab_t static fnctab_t fnctab[] = { { QSE_T("fork"), { { 0, 0 }, fnc_fork } }, + { QSE_T("getpid"), { { 0, 0 }, fnc_getpid } }, + { QSE_T("getppid"), { { 0, 0 }, fnc_getppid } }, { QSE_T("kill"), { { 2, 2 }, fnc_kill } }, { QSE_T("sleep"), { { 1, 1 }, fnc_sleep } }, { QSE_T("wait"), { { 1, 1 }, fnc_wait } } diff --git a/qse/samples/awk/awk08.cpp b/qse/samples/awk/awk08.cpp index f93e9960..c0ca4c13 100644 --- a/qse/samples/awk/awk08.cpp +++ b/qse/samples/awk/awk08.cpp @@ -36,6 +36,8 @@ # include # include # include +# include +# define USE_LTDL #endif /* these three definitions for doxygen cross-reference */ @@ -468,8 +470,16 @@ int qse_main (int argc, qse_achar_t* argv[]) qse_setdflcmgrbyid (QSE_CMGR_SLMB); #endif +#if defined(USE_LTDL) + lt_dlinit (); +#endif + ret = qse_runmain (argc, argv, awk_main); +#if defined(USE_LTDL) + lt_dlexit (); +#endif + #if defined(_WIN32) WSACleanup (); #endif