Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R shuts down when trying to run dwnominate on mac #1

Closed
dakrae opened this issue Jul 10, 2017 · 21 comments
Closed

R shuts down when trying to run dwnominate on mac #1

dakrae opened this issue Jul 10, 2017 · 21 comments
Labels

Comments

@dakrae
Copy link

dakrae commented Jul 10, 2017

Hi,

I am trying to run the dwnominate function in Rstudio (Version 1.0.143), running R version 3.4.0 on a mac (macOS 10.12.5) machine. I use rollcall data of Swiss MPs. It first successfully computes the W-NOMINATE scores, but then R always shuts down (I attached a screenshot of the error message):

bildschirmfoto 2017-07-10 um 19 11 18

Is there a problem with the fact that I try to run this on mac? Do I have to first Install the Fortran program of Poole on my machine or does this get done by default when I install the R-package? And if I have to first install the Fortran program, is this even possible on a mac machine?

I am very new to working with Fortran, I hope, someone can help me.

Thank you!

David

@wmay
Copy link
Owner

wmay commented Jul 10, 2017

I'm pretty sure this is an obscure compiler optimization issue, caused by macs using an older version of the gfortran compiler. I think it can be fixed by using a lower optimization setting.

To do that, first download this repository. Then create a file called Makevars in the src directory. Inside the Makevars file, put

mypackage_FFLAGS = $(FPICFLAGS) $(SHLIB_FFLAGS) 
all: $(SHLIB)
dwnom3.o: dwnom3.f
	$(F77) $(mypackage_FFLAGS) -O1 -pipe -g -c -o dwnom3.o dwnom3.f

Now open the terminal and run

R CMD INSTALL path/to/dwnominate-master

If you can confirm that it works after that I'll try to set up a Makevars here to make that happen automatically. Should've done that a long time ago.

Oh! And can you please tell me what you get when you run gfortran --version in your terminal?

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

Thank you for the fast answer! I tried this, but I get the following errors in the terminal when running the INSTALL command:

* installing to library '/Library/Frameworks/R.framework/Versions/3.4/Resources/library'
* installing *source* package 'dwnominate' ...
** libs
gfortran   -fPIC  -g -O2  -c Makevars.f -o Makevars.o
Makevars.f:1:1:

 mypackage_FFLAGS = $(FPICFLAGS) $(SHLIB_FFLAGS)
 1
Error: Non-numeric character in statement label at (1)
Makevars.f:1:20:

 mypackage_FFLAGS = $(FPICFLAGS) $(SHLIB_FFLAGS)
                    1
Error: Invalid character in name at (1)
Makevars.f:2:1:

 all: $(SHLIB)
 1
Error: Non-numeric character in statement label at (1)
Makevars.f:2:1:

 all: $(SHLIB)
 1
Error: Unclassifiable statement at (1)
Makevars.f:3:1:

 dwnom3.o: dwnom3.f
 1
Error: Non-numeric character in statement label at (1)
Makevars.f:3:1:

 dwnom3.o: dwnom3.f
 1
Error: Unclassifiable statement at (1)
Makevars.f:4:5:

     $(F77) $(mypackage_FFLAGS) -O1 -pipe -g -c -o dwnom3.o dwnom3.f
     1
Error: Non-numeric character in statement label at (1)
Makevars.f:4:5:

     $(F77) $(mypackage_FFLAGS) -O1 -pipe -g -c -o dwnom3.o dwnom3.f
     1
Error: Unclassifiable statement at (1)
make: *** [Makevars.o] Error 1
ERROR: compilation failed for package 'dwnominate'
* removing '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/dwnominate'
* restoring previous '/Library/Frameworks/R.framework/Versions/3.4/Resources/library/dwnominate'

I am not sure, whether I did the part with the Makevars-file right. Is this supposed to be a .f Fortran file or does it have to have some other extension than Makevars.f?

The gfortran --version command gives me the following output:

GNU Fortran (GCC) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Thank you very much for your help!

@wmay
Copy link
Owner

wmay commented Jul 11, 2017

Just name the file Makevars-- no extension.

You actually have a newer gfortran version than I do. Strange.

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

aah, thank you. I have gotten the following error in the terminal now, though:

* installing to library ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library’
* installing *source* package ‘dwnominate’ ...
** libs
Makevars:4: *** missing separator.  Stop.
ERROR: compilation failed for package ‘dwnominate’
* removing ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/dwnominate’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.4/Resources/library/dwnominate’

Does the R CMD INSTALL path/to/dwnominate-master command automatically compile the "dwnom3.f" file with gfortran or do I have to do this separately by calling gfortran somehow?

I am sorry, as mentioned above, I am new to Fortran and its surroundings so my questions might be somewhat arbitrary sometimes...

@wmay
Copy link
Owner

wmay commented Jul 11, 2017

I got the same error earlier when the last line of Makevars started with spaces instead of a tab. So make sure that line starts with a tab (maybe it got copied incorrectly somehow) and try it.

I don't know all of the details about how R CMD INSTALL finds your fortran compiler but yes it usually compiles fortran with gfortran.

I'm not so big on fortran myself-- I wrote this R package so I could avoid it. :)

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

Alright, now it installed something, but after trying to run it in R it still aborts after the W-NOMINATE estimation. By the way, it creates all the files it needs to create (e.g. "DW-NOMSTART.DAT" and "DWNOM21.DAT") and aborts after that.
When installing with the terminal, i have gotten a bunch of error messages, maybe this has something to do with it:

* installing to library '/Library/Frameworks/R.framework/Versions/3.4/Resources/library'
* installing *source* package 'dwnominate' ...
** libs
gfortran -fPIC  -O1 -pipe -g -c -o dwnom3.o dwnom3.f
dwnom3.f:6848:72:

    10 ASSIGN 30 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:6853:16:

    20 GO TO NEXT, (30, 40, 70, 80)
                1
Warning: Deleted feature: Assigned GOTO statement at (1)
dwnom3.f:6855:72:

       ASSIGN 40 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:6861:72:

       ASSIGN 70 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:6865:72:

       ASSIGN 80 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:5684:46:

      &                ' specified. ', MSGLEN, MSGSAV, MSGLEN)
                                              1
Warning: Rank mismatch in argument 'str2' at (1) (scalar and rank-1)
dwnom3.f:6443:37:

      &                '1. ', MSGLEN, MSGSAV, MSGLEN)
                                     1
Warning: Rank mismatch in argument 'str2' at (1) (scalar and rank-1)
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o dwnominate.so dwnom3.o -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: could not create compact unwind for _search_: stack subq instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _dwnominate_: stack subq instruction is too different from dwarf stack size
installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/dwnominate/libs
** R
** preparing package for lazy loading
** help
No man pages found in package  'dwnominate' 
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (dwnominate)

@wmay
Copy link
Owner

wmay commented Jul 11, 2017

Can you send me the data and script you're using? Then I could see if it runs for me, suggesting a compiler issue. If I get the segfault too then the problem is probably somewhere else.

In the meantime you can try replacing -O1 with -O0 (no compiler optimization at all) and see if that works.

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

I have sent it to your email. I tried the --O0 version as well, which did not work as well...

@wmay
Copy link
Owner

wmay commented Jul 11, 2017

Alright. The example worked for me. (You were testing this with just the two sessions, right?) I'm using gfortran 5, so if you're able to switch your gfortran version that's worth a try.

I'll experiment with gfortran 6 to see if I can find the issue, but I have no idea how long that'll take me.

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

Alright, good to hear that it at least could work with my data. ;) Yes, I was testing it with two sessions, I have data for the last 20 years.
I installed gfortran 5.2 and uninstalled my version first, but got the same errors when running R CMD INSTALL and my R session still aborted at the same point.

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

Which macos do you use by the way (I use 10.12.5)? Maybe it has something to do with that? Or with the R version (I use 3.4.1 now).

@wmay
Copy link
Owner

wmay commented Jul 11, 2017

I'm on Linux (Ubuntu 16.04), and I also have R 3.4.1. My specific gfortran version is 5.4.0.

@dakrae
Copy link
Author

dakrae commented Jul 11, 2017

Oh, so if you use Linux, it might be a problem with mac? I think gfortran 5.4 does not exist for mac, at least not here.

@wmay
Copy link
Owner

wmay commented Jul 11, 2017

OK, I got some advice from my local fortran guru.

Add -fbacktrace to the last line of Makevars. Then when you run this and get the segfault it should print out some useful information about what went wrong.

You can also try running ulimit -s unlimited in a terminal, and then run R in that terminal and try dwnominate there, which will help if your operating system is not allowing dwnominate to use the resources it requires.

@dakrae
Copy link
Author

dakrae commented Jul 12, 2017

Alright, this is what the terminal printed when using -fbacktrace in the last line of Makevars:

* installing to library '/Library/Frameworks/R.framework/Versions/3.4/Resources/library'
* installing *source* package 'dwnominate' ...
** libs
gfortran -fPIC   -O1 -pipe -g -c -o dwnom3.o dwnom3.f -fbacktrace
dwnom3.f:6848:72:

    10 ASSIGN 30 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:6853:16:

    20 GO TO NEXT, (30, 40, 70, 80)
                1
Warning: Deleted feature: Assigned GOTO statement at (1)
dwnom3.f:6855:72:

       ASSIGN 40 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:6861:72:

       ASSIGN 70 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:6865:72:

       ASSIGN 80 TO NEXT
                                                                        1
Warning: Deleted feature: ASSIGN statement at (1)
dwnom3.f:5684:46:

      &                ' specified. ', MSGLEN, MSGSAV, MSGLEN)
                                              1
Warning: Rank mismatch in argument 'str2' at (1) (scalar and rank-1)
dwnom3.f:6443:37:

      &                '1. ', MSGLEN, MSGSAV, MSGLEN)
                                     1
Warning: Rank mismatch in argument 'str2' at (1) (scalar and rank-1)
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o dwnominate.so dwnom3.o -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0'
ld: warning: could not create compact unwind for _search_: stack subq instruction is too different from dwarf stack size
ld: warning: could not create compact unwind for _dwnominate_: stack subq instruction is too different from dwarf stack size
installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/dwnominate/libs
** R
** preparing package for lazy loading
** help
No man pages found in package  'dwnominate' 
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (dwnominate)

I'm not sure whether it is that much different from the output I got before.

@dakrae
Copy link
Author

dakrae commented Jul 12, 2017

This is interesting! I was not able to change the ulimit (it might not be possible on mac), but I nevertheless ran everything in an R session in the Terminal. And this did not just break down like R does, but it gave me a specific error message:

Writing input files...
                                                               r
                                                               r
                                                               l
                                                               l
                                                               s
                                                               r
                                                               t
                                                               N
    2    1    1    2    2    5
At line 157 of file dwnom3.f
Fortran runtime error: Expected REAL for item 2 in formatted transfer, got CHARACTER
(15F8.4)
   ^

Maybe this helps you find out where the problem is?
Thank you!

@wmay
Copy link
Owner

wmay commented Jul 12, 2017

Can you send me your DW-NOMSTART.DAT file? It looks like it's not being read or written correctly.

For example, here's what my DW-NOMSTART.DAT looked like when I ran your example:

rollcall_input.dat
rollcall_output.dat
legislator_input.dat
legislator_output.dat
session_info.num
rollcall_matrix.vt3
transposed_rollcall_matrix.vt3
NOMINAL DYNAMIC-WEIGHTED MULTIDIMENSIONAL UNFOLDING 
    2    1    1    2    2    5
  5.9539  0.3463

@dakrae
Copy link
Author

dakrae commented Jul 13, 2017

I sent it to you by email. I also attached all the other data that dwnominate created.

@wmay
Copy link
Owner

wmay commented Jul 13, 2017

I didn't get the email, can you send it again?

@wmay wmay added the bug label Jul 16, 2017
@wmay
Copy link
Owner

wmay commented Jul 21, 2017

I have it on good authority that the code will run correctly if you get the version of gfortran described in this stackoverflow question.

I'm going to wait to hear more from the gfortran people before deciding what to do with this. And I'll try to get a Mac for testing so we don't have to go back and forth via email anymore.

@dakrae
Copy link
Author

dakrae commented Jul 22, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants