std::cout and gfortran print*, don't output to the screen


 
Thread Tools Search this Thread
Top Forums Programming std::cout and gfortran print*, don't output to the screen
# 1  
Old 03-28-2011
[SOLVED] std::cout and gfortran print*, don't output to the screen

I am not sure where to post this other than here.

I am trying to figure out why an app gives different output when compiled under Ubuntu 10.10 and CentOS 5.5. I am pretty sure that the issue is that the Cent version has gcc 4.1 installed, while Ubuntu has gcc 4.4. I am trying to print from some fortran code using print*, as I have always done, but nothing appears on the terminal. I don't know how to debug this if I can't print any intermediary output.

I also tried std::cout << from inside the cpp code, but that doesn't do anything either. There aren't any compiler errors or warnings, so what did I miss? Smilie

Any suggestions???

LMHmedchem

Last edited by LMHmedchem; 03-30-2011 at 03:27 PM..
# 2  
Old 03-29-2011
Hi.

It seems to work for me:
Code:
#!/usr/bin/env bash

# @(#) s1	Demonstrate compile, execute with gfortran, g++.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for i;do printf "%s" "$i";done; printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && . $C g++ gfortran

pl " File hi.f:"
cat hi.f

pl " Results, hi.f:"
rm -f a.out
gfortran hi.f
./a.out

pl " File hi.cpp:"
cat hi.cpp

pl " Results, hi.cpp:"
rm -f a.out
g++ hi.cpp
./a.out

rm -f a.out

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = en_US.UTF-8
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.18-194.32.1.el5, i686
Distribution        : CentOS release 5.5 (Final) 
GNU bash 3.2.25
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)
gfortran GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)

-----
 File hi.f:
	program hi
	write(*,*) " Hello, world with write * *"
	print*, " Hello, world with print *"
	end

-----
 Results, hi.f:
  Hello, world with write * *
  Hello, world with print *

-----
 File hi.cpp:
#include <iostream>

using namespace std;

int main()
{
  cout << " Hello, world from c++ with cout" << endl;
  return ( 0 );
}

-----
 Results, hi.cpp:
 Hello, world from c++ with cout

Standard advice:
Quote:
Advice to posters who do not post source:

If you want your program to be analyzed you should post your
program instead of trying only to describe it. Please post the
smallest code that exhibits the symptoms you have. Place the
post in CODE tags for easy reading.
Best wishes ... cheers, drl
# 3  
Old 03-29-2011
I think that the root of the problem is that this is a parent child pair of programs. The parent uses fork to create a child process, and I am trying to print from the child process code. Under Cygwin windows, adding print statements results in output to the cygwin bash shell, but for some reason this doesn't seem to work under linux. There are some differences in the code base because of the differences in windows and posix pipes, fork/create_process, etc. I suspect that in linux, the child runs in a background shell, or something like that, and so the output doesn't come to the terminal that launched the parent, if that makes any sense.

Is there any way to test this theory or resolve the issue if I am correct?

LMHmedchem
# 4  
Old 03-29-2011
Child processes should print to the terminal fine unless you created them in a very strange way. After all, every single command you run in a shell is a child process...

Whether this is true or not I cannot begin to guess because I can't see your computer from here, so have no more than a vague description that you "might" have done something in an odd way.

Is it something you did? Maybe. Maybe not. Post the code.

Last edited by Corona688; 03-29-2011 at 01:08 PM..
# 5  
Old 03-29-2011
Quote:
Originally Posted by Corona688
Child processes should print to the terminal fine unless you created them in a very strange way.

Whether this is true or not I cannot begin to guess because I can't see your computer from here, so have no more than a vague description that you "might" have done something in an odd way.

Is it something you did? Maybe. Maybe not. Post the code.
The only reference to fork is, ichpid = fork(); and then ichpid is used.

I can't post all of this code without various kinds of permission. I have a version of it that has been cleared, but it will take a bit to add the linux components and such. The cleared version is the widows code.

I just don't under stand why it doesn't print to the terminal. I have tried in CentOS, and Ubuntu and get the same results. There are no fortran header files, so there can't be a missing include, even if the compiler would let it go. Am I missing a compiler flag or something like that? I could post the make file if that would help. The only difference between the windows and linux versions are the src files for the parent and child main functions, and an auxilary functions src file. That is a very small part of the code and the rest is the same for win/lin. I don't really understand why this works in cygwin bash, but not linux bash. Both are using the gcc3.4 family.

LMHmedchem
# 6  
Old 03-29-2011
Quote:
Originally Posted by LMHmedchem
The only reference to fork is, ichpid = fork(); and then ichpid is used.
The fork isn't relevant. What's relevant is what redirections have been done before and/or after it, if any.
Quote:
I just don't under stand why it doesn't print to the terminal.
How do you know it's printing at all?
Quote:
I have tried in CentOS, and Ubuntu and get the same results.
Moving a sick sheep from place to place won't fix the sheep.
Quote:
There are no fortran header files, so there can't be a missing include, even if the compiler would let it go. Am I missing a compiler flag or something like that?
There's no "stop consoles from working" compiler flag, no. I suspect it's something internal to the program.
Quote:
I could post the make file if that would help.
Not really.
Quote:
The only difference between the windows and linux versions are the src files for the parent and child main functions, and an auxilary functions src file. That is a very small part of the code and the rest is the same for win/lin. I don't really understand why this works in cygwin bash, but not linux bash. Both are using the gcc3.4 family.
I suspect differences in paths and such are preventing sub-programs from launching. Remember that UNIX in general is case-sensitive while Windows is not.

Trace every step of the process. Put print statements in places so you can see where the execution stops.

Of course, I'm only making wild guesses. Without seeing the code that's the best any of us can do.
# 7  
Old 03-29-2011
Hi.
Quote:
'Newton is reported to have said, regarding the problem of the
Moon's orbit "It causeth my head to ache."'

from Celestial mechanics - Wikipedia, the free encyclopedia
So with me and Windows.

In case you missed the earlier entry:
Quote:
Advice to posters who do not post source:

If you want your program to be analyzed you should post your
program instead of trying only to describe it. Please post the
smallest code that exhibits the symptoms you have
. Place the
post in CODE tags for easy reading.
That may mean that you may need to do some coding to try to elicit the symptoms with the smallest code. If you are reluctant, then we can be of little of no help.

I am disengaging from this thread.

Best of luck ... cheers, drl
This User Gave Thanks to drl For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

awk: don't print sub-arrays

Hi ! I have this input: 12{11}{11110}{80}3456 {123}15{60}9876{8083}34 I try to work on individual numbers between braces. 3 possible cases (here I used colours to be clearer only): - there is no "0" among the characters between braces: so we don't touch anything. - there is a "0" among... (4 Replies)
Discussion started by: beca123456
4 Replies

2. Solaris

Camouflage STD IN on output (TRU64)

Hi guys, i have a new problem, even in scripting on KSH. Given a string by standard INPUT (keyboard), i need to replace each character i print with this one '#' . It's to camouflage password while digiting on command line. For example: ---------------------------------- prompt$ ... (3 Replies)
Discussion started by: D4vid
3 Replies

3. UNIX for Dummies Questions & Answers

how to print script output to screen and file

Hi all, I have a script that bulk loads thousands of lines of data. I need to log the output during the execution of the script. I know I can redirect (">") the output to a file; however, I want the output going to both the screen and the log file. I thought I could use pipe to pipe the... (10 Replies)
Discussion started by: orahi001
10 Replies

4. UNIX for Advanced & Expert Users

redirect to both file and std output at the same time

hello can some one please help me to redirect the output of a command to both std output and a file. this is little urgent. sridhar (2 Replies)
Discussion started by: send2sridhar
2 Replies

5. AIX

Redirecting Both to a file and std output

Hello Friends, Can some one help me how to redirect output of a file to both a file and std output? All the help would be greatly appreciated. Regards Sridhar (1 Reply)
Discussion started by: send2sridhar
1 Replies

6. UNIX for Dummies Questions & Answers

cout doesn't print everything

Hi all, I implemented a C++ program and successfully compiled and ran on my laptop. However when I copy my code to another machine (school's sun machine), it didn't run properly. I can compile and run, but cout does not print everything. I used cout in a loop where it iterates no more than 20... (5 Replies)
Discussion started by: SaTYR
5 Replies

7. Shell Programming and Scripting

awk to compare lines of two files and print output on screen

hey guys, I have two files both with two columns, I have already created an awk code to ignore certain lines (e.g lines that start with 963) as they wou ld begin with a certain string, however, the rest I have added together and calculated the average. At the moment the code also displays... (3 Replies)
Discussion started by: chlfc
3 Replies

8. Programming

Sun Studio C++ - Getting error in linking std::ostream &std::ostream::operator<<(std:

Hello all Im using CC: Sun C++ 5.6 2004/07/15 and using the -library=stlport4 when linkning im getting The fallowing error : Undefined first referenced symbol in file std::ostream &std::ostream::operator<<(std::ios_base&(*)(std::ios_base&))... (0 Replies)
Discussion started by: umen
0 Replies

9. Programming

Why I don't get any output?

Hello, I am very new in writing low level programming in C. I am trying to get an output in Linux 2.6.17.6 gentoo platform, but I don't get any output. I am trying to do the following: I am trying to scan a word and print its content at the standard output by using sscanf and printf. I... (6 Replies)
Discussion started by: Sharmin
6 Replies

10. Shell Programming and Scripting

How to redirect std out and std err to same file

Hi I want both standard output and standard error of my command cmd to go to the same file log.txt. please let me know the best commandline to do this. Thanks (2 Replies)
Discussion started by: 0ktalmagik
2 Replies
Login or Register to Ask a Question