Compare commits

...

9 Commits

Author SHA1 Message Date
Thomas Koenig
6857bd99f3 multi.c: Remove static variables _gfortrani_caf_this_image and caf_num_images.
2018-09-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
	* caf/multi.c: Remove static variables _gfortrani_caf_this_image
	and caf_num_images.
	* runtime/environ.c: Add caf_num_images.
	* runtime/compile_options.c: Add _gfortrani_caf_this_image.

From-SVN: r264045
2018-09-02 20:10:58 +00:00
Thomas Koenig
8d3339526a multi.c (_gfortran_caf_register): New function.
2018-09-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* caf/multi.c (_gfortran_caf_register): New function.
	(_gfortran_caf_lock): New function.
	(_gfortran_caf_unlock): New function.

From-SVN: r264044
2018-09-02 18:31:54 +00:00
Thomas Koenig
72a7867c5c multi.c (_gfortran_caf_sync_images): Handle SYNC IMAGGES (*) correctly.
2018-09-02  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* caf/multi.c (_gfortran_caf_sync_images): Handle
	SYNC IMAGGES (*) correctly.

From-SVN: r264041
2018-09-02 15:08:47 +00:00
Thomas Koenig
88c90cf10b trans-decl.c (create_main_function): Move call of _gfortran_caf_init right before cal to MAIN__().
2018-09-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
	    Nicolas Koenig  <koenigni@gcc.gnu.org>

	* trans-decl.c (create_main_function): Move call of
	_gfortran_caf_init right before cal to MAIN__().

2018-09-02  Thomas Koenig  <tkoenig@gcc.gnu.org>
	    Nicolas Koenig <koenigni@gcc.gnu.org>

	* caf/multi.c: Some cleanup.
	(image_num): Rename to _gfortrani_caf_this_image.
	(sim): New static variable.
	(cim): Likewise.
	(cond_t): New type.
	(init_image): Some reformatting.
	(_gfortran_caf_init): Handle arrays of conditions and number for
	sync images.
	(cond_init): New function.
	(cond_wait): New function.
	(cond_signal): New function.
	(A): Macro to simplify array access.
	(_gfortran_caf_sync_images): New function.
	* libgfortran.h (caf_num_images): New static variable.
	(_gfortrani_caf_this_image): New static variable.
	* runtime/compile_options.c (set_options): Return early if
	we are in a dependent image.
	* runtime/environ.c (static_variable_table): Add
	GFORTRAN_CAF_IMAGES with default of 4.
	* runtime/main.c (set_args): Return early if we are in a
	dependent variable.


Co-Authored-By: Nicolas Koenig <koenigni@gcc.gnu.org>

From-SVN: r264040
2018-09-02 14:22:29 +00:00
Nicolas Koenig
98ca827ea5 [multiple changes]
2018-08-28  Nicolas Koenig  <koenigni@gcc.gnu.org>
	
	* caf/multi.c: New file

2018-08-26  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	* Development log for native coarray fortran.

2018-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* Merged branch from r263319 to r263752.

2018-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* libgfortran/Makefile.am: Added handling of multi.c library.
	* libgfortran/Makefile.in: Regenerated.
	* libgfortran/caf/multi.c: New file (for now, just
	copied over from single.c).

From-SVN: r263924
2018-08-28 16:29:54 +00:00
Thomas Koenig
f807db286b ChangeLog-caf: Deleted and put info into
2018-08-27  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* ChangeLog-caf: Deleted and put info into
	* gcc/fortran/ChangeLog.dev: Here and
	* libgfortran/ChangeLog.dev: Here.

From-SVN: r263894
2018-08-27 19:47:42 +00:00
Jerry DeLisle
d0589f4a7d 2018-08-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
* Development logs for native coarray fortran.

From-SVN: r263868
2018-08-27 02:35:20 +00:00
Thomas Koenig
f80f23a4df Changelog-caf: New file.
2018-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* Changelog-caf: New file.
	* Merged branch from r263319 to r263752.

2018-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* libgfortran/Makefile.am: Added handling of multi.c library.
	* libgfortran/Makefile.in: Regenerated.
	* libgfortran/caf/multi.c: New file (for now, just
	copied over from single.c).

From-SVN: r263754
2018-08-21 21:19:34 +00:00
Thomas Koenig
ceb3bc68d3 Changelog-caf: New file.
2018-08-21  Thomas Koenig  <tkoenig@gcc.gnu.org>

        * Changelog-caf: New file.
        * Merged branch from r263319 to r263750.

From-SVN: r263753
2018-08-21 20:17:38 +00:00
16 changed files with 486 additions and 39 deletions

8
gcc/configure vendored
View File

@@ -19731,20 +19731,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
prelink_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
old_archive_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
$RANLIB $oldlib'
archive_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
archive_expsym_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
;;
*) # Version 6 and above use weak symbols
archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'

13
gcc/fortran/ChangeLog.dev Normal file
View File

@@ -0,0 +1,13 @@
2018-09-02 Thomas Koenig <tkoenig@gcc.gnu.org>
Nicolas Koenig <koenigni@gcc.gnu.org>
* trans-decl.c (create_main_function): Move call of
_gfortran_caf_init right before cal to MAIN__().
2018-08-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
* Development log for native coarray fortran.
2018-08-21 Thomas Koenig <tkoenig@gcc.gnu.org>
* Merged branch from r263319 to r263752.

View File

@@ -5969,20 +5969,6 @@ create_main_function (tree fndecl)
/* Call some libgfortran initialization routines, call then MAIN__(). */
/* Call _gfortran_caf_init (*argc, ***argv). */
if (flag_coarray == GFC_FCOARRAY_LIB)
{
tree pint_type, pppchar_type;
pint_type = build_pointer_type (integer_type_node);
pppchar_type
= build_pointer_type (build_pointer_type (pchar_type_node));
tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_init, 2,
gfc_build_addr_expr (pint_type, argc),
gfc_build_addr_expr (pppchar_type, argv));
gfc_add_expr_to_block (&body, tmp);
}
/* Call _gfortran_set_args (argc, argv). */
TREE_USED (argc) = 1;
TREE_USED (argv) = 1;
@@ -6088,6 +6074,20 @@ create_main_function (tree fndecl)
gfc_add_expr_to_block (&body, tmp);
}
/* Call _gfortran_caf_init (*argc, ***argv). */
if (flag_coarray == GFC_FCOARRAY_LIB)
{
tree pint_type, pppchar_type;
pint_type = build_pointer_type (integer_type_node);
pppchar_type
= build_pointer_type (build_pointer_type (pchar_type_node));
tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_init, 2,
gfc_build_addr_expr (pint_type, argc),
gfc_build_addr_expr (pppchar_type, argv));
gfc_add_expr_to_block (&body, tmp);
}
/* Call MAIN__(). */
tmp = build_call_expr_loc (input_location,
fndecl, 0);

8
libcc1/configure vendored
View File

@@ -12221,20 +12221,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
prelink_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
old_archive_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
$RANLIB $oldlib'
archive_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
archive_expsym_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
;;
*) # Version 6 and above use weak symbols
archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'

61
libgfortran/ChangeLog.dev Normal file
View File

@@ -0,0 +1,61 @@
2018-09-02 Thomas Koenig <tkoenig@gcc.gnu.org>
* caf/multi.c: Remove static variables _gfortrani_caf_this_image
and caf_num_images.
* runtime/environ.c: Add caf_num_images.
* runtime/compile_options.c: Add _gfortrani_caf_this_image.
2018-09-02 Thomas Koenig <tkoenig@gcc.gnu.org>
* caf/multi.c (_gfortran_caf_register): New function.
(_gfortran_caf_lock): New function.
(_gfortran_caf_unlock): New function.
2018-09-02 Thomas Koenig <tkoenig@gcc.gnu.org>
* caf/multi.c (_gfortran_caf_sync_images): Handle
SYNC IMAGGES (*) correctly.
2018-09-02 Thomas Koenig <tkoenig@gcc.gnu.org>
Nicolas Koenig <koenigni@gcc.gnu.org>
* caf/multi.c: Some cleanup.
(image_num): Rename to _gfortrani_caf_this_image.
(sim): New static variable.
(cim): Likewise.
(cond_t): New type.
(init_image): Some reformatting.
(_gfortran_caf_init): Handle arrays of conditions and number for
sync images.
(cond_init): New function.
(cond_wait): New function.
(cond_signal): New function.
(A): Macro to simplify array access.
(_gfortran_caf_sync_images): New function.
* libgfortran.h (caf_num_images): New static variable.
(_gfortrani_caf_this_image): New static variable.
* runtime/compile_options.c (set_options): Return early if
we are in a dependent image.
* runtime/environ.c (static_variable_table): Add
GFORTRAN_CAF_IMAGES with default of 4.
* runtime/main.c (set_args): Return early if we are in a
dependent variable.
2018-08-28 Nicolas Koenig <koenigni@gcc.gnu.org>
* caf/multi.c: New file
2018-08-26 Jerry DeLisle <jvdelisle@gcc.gnu.org>
* Development log for native coarray fortran.
2018-08-21 Thomas Koenig <tkoenig@gcc.gnu.org>
* Merged branch from r263319 to r263752.
2018-08-21 Thomas Koenig <tkoenig@gcc.gnu.org>
* libgfortran/Makefile.am: Added handling of multi.c library.
* libgfortran/Makefile.in: Regenerated.
* libgfortran/caf/multi.c: New file (for now, just
copied over from single.c).

View File

@@ -43,12 +43,16 @@ libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
$(version_arg) -Wc,-shared-libgcc
libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP)
cafexeclib_LTLIBRARIES = libcaf_single.la
cafexeclib_LTLIBRARIES = libcaf_single.la libcaf_multi.la
cafexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)
libcaf_single_la_SOURCES = caf/single.c
libcaf_single_la_LDFLAGS = -static
libcaf_single_la_DEPENDENCIES = caf/libcaf.h
libcaf_single_la_LINK = $(LINK) $(libcaf_single_la_LDFLAGS)
libcaf_multi_la_SOURCES = caf/multi.c
libcaf_multi_la_LDFLAGS = -static
libcaf_multi_la_DEPENDENCIES = caf/libcaf.h
libcaf_multi_la_LINK = $(LINK) $(libcaf_multi_la_LDFLAGS)
if IEEE_SUPPORT
fincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/finclude

View File

@@ -182,6 +182,9 @@ am__installdirs = "$(DESTDIR)$(cafexeclibdir)" \
"$(DESTDIR)$(toolexeclibdir)" "$(DESTDIR)$(toolexeclibdir)" \
"$(DESTDIR)$(fincludedir)"
LTLIBRARIES = $(cafexeclib_LTLIBRARIES) $(toolexeclib_LTLIBRARIES)
libcaf_multi_la_LIBADD =
am_libcaf_multi_la_OBJECTS = multi.lo
libcaf_multi_la_OBJECTS = $(am_libcaf_multi_la_OBJECTS)
libcaf_single_la_LIBADD =
am_libcaf_single_la_OBJECTS = single.lo
libcaf_single_la_OBJECTS = $(am_libcaf_single_la_OBJECTS)
@@ -441,7 +444,8 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
FCCOMPILE = $(FC) $(AM_FCFLAGS) $(FCFLAGS)
LTFCCOMPILE = $(LIBTOOL) --tag=FC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=compile $(FC) $(AM_FCFLAGS) $(FCFLAGS)
SOURCES = $(libcaf_single_la_SOURCES) $(libgfortran_la_SOURCES)
SOURCES = $(libcaf_multi_la_SOURCES) $(libcaf_single_la_SOURCES) \
$(libgfortran_la_SOURCES)
MULTISRCTOP =
MULTIBUILDTOP =
MULTIDIRS =
@@ -629,12 +633,16 @@ libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
$(version_arg) -Wc,-shared-libgcc
libgfortran_la_DEPENDENCIES = $(version_dep) libgfortran.spec $(LIBQUADLIB_DEP)
cafexeclib_LTLIBRARIES = libcaf_single.la
cafexeclib_LTLIBRARIES = libcaf_single.la libcaf_multi.la
cafexeclibdir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)
libcaf_single_la_SOURCES = caf/single.c
libcaf_single_la_LDFLAGS = -static
libcaf_single_la_DEPENDENCIES = caf/libcaf.h
libcaf_single_la_LINK = $(LINK) $(libcaf_single_la_LDFLAGS)
libcaf_multi_la_SOURCES = caf/multi.c
libcaf_multi_la_LDFLAGS = -static
libcaf_multi_la_DEPENDENCIES = caf/libcaf.h
libcaf_multi_la_LINK = $(LINK) $(libcaf_multi_la_LDFLAGS)
@IEEE_SUPPORT_TRUE@fincludedir = $(libdir)/gcc/$(target_alias)/$(gcc_version)$(MULTISUBDIR)/finclude
@IEEE_SUPPORT_TRUE@nodist_finclude_HEADERS = ieee_arithmetic.mod ieee_exceptions.mod ieee_features.mod
AM_CPPFLAGS = -iquote$(srcdir)/io -I$(srcdir)/$(MULTISRCTOP)../gcc \
@@ -1528,6 +1536,8 @@ clean-toolexeclibLTLIBRARIES:
echo "rm -f \"$${dir}/so_locations\""; \
rm -f "$${dir}/so_locations"; \
done
libcaf_multi.la: $(libcaf_multi_la_OBJECTS) $(libcaf_multi_la_DEPENDENCIES) $(EXTRA_libcaf_multi_la_DEPENDENCIES)
$(libcaf_multi_la_LINK) -rpath $(cafexeclibdir) $(libcaf_multi_la_OBJECTS) $(libcaf_multi_la_LIBADD) $(LIBS)
libcaf_single.la: $(libcaf_single_la_OBJECTS) $(libcaf_single_la_DEPENDENCIES) $(EXTRA_libcaf_single_la_DEPENDENCIES)
$(libcaf_single_la_LINK) -rpath $(cafexeclibdir) $(libcaf_single_la_OBJECTS) $(libcaf_single_la_LIBADD) $(LIBS)
libgfortran.la: $(libgfortran_la_OBJECTS) $(libgfortran_la_DEPENDENCIES) $(EXTRA_libgfortran_la_DEPENDENCIES)
@@ -1914,6 +1924,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minval_r4.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/minval_r8.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/move_alloc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/multi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mvbits.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/norm2_r10.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/norm2_r16.Plo@am__quote@
@@ -2520,6 +2531,13 @@ f2c_specifics.lo: intrinsics/f2c_specifics.F90
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
multi.lo: caf/multi.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT multi.lo -MD -MP -MF $(DEPDIR)/multi.Tpo -c -o multi.lo `test -f 'caf/multi.c' || echo '$(srcdir)/'`caf/multi.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/multi.Tpo $(DEPDIR)/multi.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='caf/multi.c' object='multi.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) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o multi.lo `test -f 'caf/multi.c' || echo '$(srcdir)/'`caf/multi.c
single.lo: caf/single.c
@am__fastdepCC_TRUE@ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT single.lo -MD -MP -MF $(DEPDIR)/single.Tpo -c -o single.lo `test -f 'caf/single.c' || echo '$(srcdir)/'`caf/single.c
@am__fastdepCC_TRUE@ $(am__mv) $(DEPDIR)/single.Tpo $(DEPDIR)/single.Plo

333
libgfortran/caf/multi.c Normal file
View File

@@ -0,0 +1,333 @@
/* Pthread based coarray implementation of GNU Fortran Coarray Library
Copyright (C) 2011-2018 Free Software Foundation, Inc.
Contributed by Jerry DeLisle <jvdelisle@gcc.gnu.org>,
Thomas Koenig <tkoenig@gcc.gnu.org>,
Nicolas Koenig <koenigni@gcc.gnu.org>
This file is part of the GNU Fortran Coarray Runtime Library (libcaf).
Libcaf is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
Libcaf 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 General Public License for more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include "libcaf.h"
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
/* Currently compile programs which call this with
$ gfortran -static-libgfortran -fcoarray=lib foo.f90 -pthread -lcaf_multi
*/
int main(int argc, char **argv);
/* Types. */
typedef struct {
int this_image;
int argc;
char **argv;
} init_args;
typedef struct {
void **base_array;
} caf_multi_token_t;
typedef struct cond_t {
pthread_cond_t cond;
int signalled;
pthread_mutex_t mutex;
} cond_t;
/* Static variables. */
pthread_barrier_t sync_all_barrier;
pthread_t *tidlist;
static int *sim;
static cond_t *cim;
static int cond_init(cond_t *cond);
static void *
init_image (void *p)
{
init_args args = *(init_args *) p;
free(p);
_gfortrani_caf_this_image = args.this_image;
pthread_barrier_wait (&sync_all_barrier);
/* XXX: Must be called since there is no other way to set the
options for the images since _gfortran_set_option is called after
_gfortran_caf_init and options is a local variable in main. It would
be better to switch to calling MAIN__ once we have the new
interface. */
main (args.argc, args.argv);
return NULL;
}
void
_gfortran_caf_init (int *argcptr, char ***argvptr)
{
init_args *args;
/* Ensure the function is only executed once after calling main
recursively. */
if (_gfortrani_caf_this_image > 0)
return;
pthread_barrier_init (&sync_all_barrier, NULL, caf_num_images);
tidlist = calloc (caf_num_images, sizeof(pthread_t));
sim = calloc(caf_num_images * caf_num_images, sizeof(int));
cim = calloc(caf_num_images * caf_num_images, sizeof(cond_t));
for (int i = 0; i < caf_num_images; i++)
cond_init(cim + i);
for (int i = 1; i < caf_num_images; i++) {
args = malloc (sizeof (init_args));
args->this_image = i;
args->argc = *argcptr;
args->argv = *argvptr;
pthread_create (tidlist + i, NULL, init_image, args);
}
tidlist[0] = pthread_self ();
_gfortrani_caf_this_image = 0;
pthread_barrier_wait (&sync_all_barrier);
}
/* Implementation of caf_register - so far only good enough to allow for
CRITICAL / END CRITICAL. */
void
_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token,
gfc_descriptor_t *data, int *stat, char *errmsg,
size_t errmsg_len)
{
if (type == CAF_REGTYPE_CRITICAL)
{
pthread_mutex_t *mutex, **mp;
mutex = malloc (sizeof *mutex);
pthread_mutex_init (mutex, NULL);
mp = token;
*mp = mutex;
}
}
/* Implement a lock. */
void
_gfortran_caf_lock (caf_token_t token, size_t index,
int image_index __attribute__ ((unused)),
int *aquired_lock, int *stat, char *errmsg, size_t errmsg_len)
{
pthread_mutex_t *mutex;
mutex = token;
pthread_mutex_lock (mutex);
}
/* Implement an unlock. */
void
_gfortran_caf_unlock (caf_token_t token, size_t index,
int image_index __attribute__ ((unused)),
int *stat, char *errmsg, size_t errmsg_len)
{
pthread_mutex_t *mutex;
mutex = token;
pthread_mutex_unlock (mutex);
}
/*
Doesn't work
void
_gfortran_caf_register (size_t size, caf_register_t type, caf_token_t *token,
gfc_descriptor_t *data, int *stat, char *errmsg,
size_t errmsg_len) {
caf_multi_token_t **t = (caf_multi_token_t **) token;
void *temp;
if (type == CAF_REGTYPE_COARRAY_STATIC)
{
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_lock(&lock);
if(!*t)
{
*t = malloc(sizeof(caf_multi_token_t));
(*t)->base_array = malloc(get_num_images()*size);
}
data->base_addr = (*t)->base_array+this_image*size;
pthread_mutex_unlock(&lock);
}
else
printf("Hm");
}
void
_gfortran_caf_send (caf_token_t token, size_t offset,
int image_index, gfc_descriptor_t *dest,
caf_vector_t *dst_vector, gfc_descriptor_t *src,
int dst_kind, int src_kind, bool may_require_tmp,
int *stat)
{
caf_multi_token_t *t = (caf_multi_token_t *) token;
*(int *) src->base_addr = ((int *) t->base_array[image_index-1])[offset];
}
void
_gfortran_caf_get (caf_token_t token, size_t offset,
int image_index __attribute__ ((unused)),
gfc_descriptor_t *src,
caf_vector_t *src_vector __attribute__ ((unused)),
gfc_descriptor_t *dest, int src_kind, int dst_kind,
bool may_require_tmp, int *stat)
{
caf_multi_token_t *t = (caf_multi_token_t *) token;
((int *) t->base_array[image_index-1])[offset] = *(int *) src->base_addr;
}
*/
void
_gfortran_caf_finalize(void)
{
int i;
if (_gfortrani_caf_this_image != 0)
pthread_exit(NULL);
for (i = 1; i < caf_num_images; i++)
pthread_join(tidlist[i], NULL);
}
int
_gfortran_caf_this_image(int distance) {
return _gfortrani_caf_this_image+1;
}
int
_gfortran_caf_num_images (int distance __attribute__ ((unused)),
int failed __attribute__ ((unused)))
{
return caf_num_images;
}
static int
cond_init(cond_t *cond)
{
pthread_mutex_init (&cond->mutex, NULL);
pthread_cond_init (&cond->cond, NULL);
cond->signalled = 0;
return 0;
}
static int
cond_wait (cond_t * cond)
{
while (!cond->signalled)
pthread_cond_wait (&cond->cond, &cond->mutex);
cond->signalled = 0;
pthread_mutex_unlock (&cond->mutex);
return 0;
}
static int
cond_signal (cond_t *cond)
{
cond->signalled = 1;
pthread_cond_signal (&cond->cond);
pthread_mutex_unlock (&cond->mutex);
return 0;
}
#define A(i,j) (sim[(i) + caf_num_images * (j)])
void
_gfortran_caf_sync_images (int count, int *images,
int *stat __attribute__ ((unused)),
char *errmsg __attribute__ ((unused)),
size_t errmsg_len __attribute__ ((unused)))
{
pthread_mutex_t *my_mutex;
if (count < 0)
count = caf_num_images;
for (int i=0; i < count; i++)
{
int other_img = images == NULL ? i : images[i] - 1;
if (other_img != _gfortrani_caf_this_image)
{
cond_t *other_thread = cim + other_img;
pthread_mutex_lock (&other_thread->mutex);
A(_gfortrani_caf_this_image, other_img) ++;
cond_signal(other_thread);
}
}
while (1)
{
int x;
int do_wait = 0;
my_mutex = &(cim[_gfortrani_caf_this_image].mutex);
pthread_mutex_lock (my_mutex);
for (int i = 0; i < count; i++)
{
int other_img = images == NULL ? i : images[i] - 1;
if (other_img != _gfortrani_caf_this_image)
{
x = A(other_img, _gfortrani_caf_this_image)
< A(_gfortrani_caf_this_image, other_img);
if (x)
{
do_wait = 1;
break;
}
}
}
if (do_wait)
cond_wait(cim + _gfortrani_caf_this_image);
else
break;
}
pthread_mutex_unlock (my_mutex);
}
#undef A
/* Probably has a race condition, if a thread reaches the barrier
before all have left, but I'm not certain how that works. */
void
_gfortran_caf_sync_all (int *stat,
char *errmsg __attribute__ ((unused)),
size_t errmsg_len __attribute__ ((unused)))
{
pthread_barrier_wait(&sync_all_barrier);
}

View File

@@ -1746,7 +1746,8 @@ void cshift1_16_c16 (gfc_array_c16 * const restrict,
internal_proto(cshift1_16_c16);
#endif
/* Define this if we support asynchronous I/O on this platform. This
currently requires weak symbols. */
extern int caf_num_images;
internal_proto(caf_num_images);
extern __thread int _gfortrani_caf_this_image;
#endif /* LIBGFOR_H */

View File

@@ -142,9 +142,19 @@ backtrace_handler (int signum)
extern void set_options (int , int []);
export_proto(set_options);
/* Thread-local storage which image we are in. */
__thread int _gfortrani_caf_this_image = -1;
void
set_options (int num, int options[])
{
/* Do not set options if we're not in the main program
of a pthread coarray application. */
if (_gfortrani_caf_this_image > 0)
return;
if (num >= 1)
compile_options.warn_std = options[0];
if (num >= 2)

View File

@@ -32,6 +32,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <unistd.h>
#endif
int caf_num_images = -1;
/* Implementation of secure_getenv() for targets where it is not
provided. */
@@ -217,6 +218,9 @@ static variable variable_table[] = {
/* Print out a backtrace if possible on runtime error */
{ "GFORTRAN_ERROR_BACKTRACE", -1, &options.backtrace, init_boolean },
/* Number of images to start with -fcoarray=pthread. */
{ "GFORTRAN_CAF_IMAGES", 4, &caf_num_images, init_integer },
{ NULL, 0, NULL, NULL }
};

View File

@@ -43,6 +43,9 @@ static char **argv_save;
void
set_args (int argc, char **argv)
{
if (_gfortrani_caf_this_image > 0)
return;
argc_save = argc;
argv_save = argv;
}

View File

@@ -40,12 +40,12 @@
/* Define to 1 if you have the <link.h> header file. */
#undef HAVE_LINK_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `lstat' function. */
#undef HAVE_LSTAT
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `readlink' function. */
#undef HAVE_READLINK

View File

@@ -13308,20 +13308,20 @@ if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
prelink_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $objs $libobjs $compile_deplibs~
compile_command="$compile_command `find $tpldir -name \*.o | $NL2SP`"'
compile_command="$compile_command `find $tpldir -name \*.o | sort | $NL2SP`"'
old_archive_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $oldobjs$old_deplibs~
$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | $NL2SP`~
$AR $AR_FLAGS $oldlib$oldobjs$old_deplibs `find $tpldir -name \*.o | sort | $NL2SP`~
$RANLIB $oldlib'
archive_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
archive_expsym_cmds_CXX='tpldir=Template.dir~
rm -rf $tpldir~
$CC --prelink_objects --instantiation_dir $tpldir $predep_objects $libobjs $deplibs $convenience $postdep_objects~
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
$CC -shared $pic_flag $predep_objects $libobjs $deplibs `find $tpldir -name \*.o | sort | $NL2SP` $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
;;
*) # Version 6 and above use weak symbols
archive_cmds_CXX='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'

View File

@@ -61,7 +61,9 @@ DIST_COMMON = ChangeLog $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
$(nobase_libsubinclude_HEADERS)
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/cet.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/lthostflags.m4 \
$(top_srcdir)/../config/multi.m4 \
@@ -69,9 +71,7 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/override.m4 \
$(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
$(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
$(top_srcdir)/../lt~obsolete.m4 \
$(top_srcdir)/../config/enable.m4 \
$(top_srcdir)/../config/cet.m4 $(top_srcdir)/configure.ac
$(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \

4
libssp/aclocal.m4 vendored
View File

@@ -989,7 +989,9 @@ AC_SUBST([am__untar])
]) # _AM_PROG_TAR
m4_include([../config/acx.m4])
m4_include([../config/cet.m4])
m4_include([../config/depstand.m4])
m4_include([../config/enable.m4])
m4_include([../config/lead-dot.m4])
m4_include([../config/lthostflags.m4])
m4_include([../config/multi.m4])
@@ -1000,5 +1002,3 @@ m4_include([../ltoptions.m4])
m4_include([../ltsugar.m4])
m4_include([../ltversion.m4])
m4_include([../lt~obsolete.m4])
m4_include([../config/enable.m4])
m4_include([../config/cet.m4])