|
OK, I am doing something stupid trying to get # of CPU's in Raspberry Pi.
This returns "syntax error : end of file unexpected " and # of CPU's 512
#include <omp.h>
int iCPU = system ("omp_get_num_procs()");
cout << "# of CPU's " << dec << +iCPU << endl;
exit(1);
Any second opinions ( leading to solution ) are welcome and appreciated.
Cheers
Vaclav
SOLVED
Was missing link to gomp library
modified 8-Feb-19 15:54pm.
|
|
|
|
|
See the man page for system() - its essentially a wrapper around execl() and vfork(). Unless you can execute "omp_get_num_procs()" from the command line, what you have won't work.
Why would you think you need a call to system() in this case?
|
|
|
|
|
This is response from CL on my PC
jim@jim-desktop $ omp_get_num_procs()
>
and this is coming from RPi
pi@pi $ jim@jim-desktop $ omp_get_num_procs()
-bash: syntax error near unexpected token `('
pi@pi $ >
-bash: syntax error near unexpected token `newline'
pi@pi $ sudo omp_get_num_procs()
The purpose / reason was posted in OP.
-bash: syntax error near unexpected token `('
pi@pi $ sudo omp_get_num_procs
sudo: omp_get_num_procs: command not found
pi@pi $
I'll check the man.
|
|
|
|
|
Let me try this another way.
In your last question to this discussion board (from "ls" to C++ buffer?) you asked about capturing the output from system() into your C++ program. I take it from that, that you know what the system() call does - i.e. calls a system command like ls, or ps or grep, etc. So now you seem to be wanting to call a function provided in the omp.h header via the system() call. That makes no sense to me. The only reason I could think you might want to do that was if you were trying to execute the function as a different user - in which case that is not the way to go about that. So my question stands - why are you trying to wrap what appears to be a normal, ordinary C function call inside a call to system()?
|
|
|
|
|
You do not need parentheses on command/program calls in the system. Change your code to:
int iCPU = system ("omp_get_num_procs");
Although I do not expect that a call to system will return the output from the command. Also I suspect you also need to wrap that code in a int main(){} block in order to compile it correctly.
|
|
|
|
|
int main() {
#ifdef STEP
cout << "Project VNAR-19270 VNA-1023 (6 base) Vector network analyzer" << endl;
cout << "DEBUG ****RUNNING WORKING COPY of VNA_2 " << endl;
#endif
int iCPU = 0;
iCPU = system ("omp_get_num_procs");
cout << "# of CPU's " << dec << +iCPU << endl;
exit(1);
Now returns omp_get_num_procs not found.
I think the problem is also in crosscompiler settings.
Also the "remote AKA RPi" OS has no OpenMP installed.
I need to check that.
I was just looking for an advise if my syntax is OK.
|
|
|
|
|
The syntax looks OK now. The error message implies the the omp_get_num_procs program cannot be found in any of the standard locations, so you may need to provide the full path. As I said before, you will not get the correct answer from the call to system ; see the man page for details. In order to get the correct number you need to connect the external command's stdout stream to your application, which you can then read and process as required.
[edit]
You need to re-read k5054's message above.
[/edit]
modified 8-Feb-19 11:54am.
|
|
|
|
|
Richard MacCutchan wrote: The error message implies the the omp_get_num_procs program cannot be found in any of the standard locations
That's not surprising omp_get_num_procs() is a function call in the OpenMP library. I'm not sure why the OP thinks that it needs to be wrapped in a call to system(). If they could answer that question, maybe we can tell him why he's mistaken, and how to fix his mistake.
|
|
|
|
|
Thanks, I see from your previous message that you have explained that.
|
|
|
|
|
int iCPU = 0;
iCPU = omp_get_num_procs();
cout << "# of CPU's " << dec << +iCPU << endl;
exit(1);
Using system( ) because without it I get
./src/VNA_1022_BASE.o: In function `main':
/media/jim/DEV/Eclipse_2019_03_M1/workspace/eclipse-workspace/VNAR_19280/Debug/../src/VNA_1022_BASE.cpp:253: undefined reference to `omp_get_num_procs'
makefile:80: recipe for target 'VNAR_19280' failed
collect2: error: ld returned 1 exit status
make: *** [VNAR_19280] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
I believe it is NOT only syntax issue, but something is missing in setting OpenMP.
I'll take a look at the verbose output of both complier and linker to see anything obvious.
|
|
|
|
|
The linker message undefined reference to `omp_get_num_procs' is the clue, here. You need to tell your IDE to link in libgomp when compiling this project.
What made you think that using system() was the right thing here?
|
|
|
|
|
Habit, used to equerry other system info.
Yes, the linker has given me a hit to check another instruction how to implement OpenMP.
The first one did not included the "link to gomp".
Not everything posted on internet is true and I should have known better anyway.
Now if I can figure out how to tell my IDE to use OpenMP I'll be a happy camper.
|
|
|
|
|
Yes, by using system you are not calling the omp_get_num_procs function at all. You need to understand the difference between using system to run an external application, and calling a library function directly. In the above case you are missing the library that contains the omp_get_num_procs function. So you just need to add it to the LIB section of your makefile, or in the linker section of your project in the IDE (not sure which one you are using here).
modified 9-Feb-19 4:39am.
|
|
|
|
|
"ls" command sends output to "cout".
How do I get it to C++ code buffer?
This code outputs desired /dev/spi x string to a console, I need it to save it in a buffer for further
processing. How?
system("ls -l -x /dev/spi*");
Cheers
Vaclav
|
|
|
|
|
use popen(). e.g.
#include <cstdio>
FILE *cmd = popen("ls -l -x /dev/spi*", "r");
while(!feof(cmd) && !ferr(cmd)) {
fscanf(cmd, ...);
}
fclose(cmd);
If you've got boost, then maybe boost.process will be a better fit.
If you just need filenames, maybe glob() is all you need
#include <glob>
glob_t spi_files;
glob("/dev/spi*", 0, 0, &spi_files);
for(size_t i = 0; i < spi_files.gl_pathc; ++i) {
char *filename = gl.pathv[i];
...
}
globfree(&spi_files);
If you need further information about the files, then you can call stat() on the file, see man stat(2). Also see man glob(3) for the usage of arguments 2 and 3 (0s in above code).
There's also boost.filesystem, which may help you. If you've got a C++17 compilant compiler (gcc v8), then you also have <filesystem> in the stdlib
|
|
|
|
|
Thanks
I just downloaded boost , like to try it, but it does not included format.
I need to figure out how to "insert" format without having to delete ( I have not (intentionally) deleted anything from my OS, scary !) boost and re-install it from a different source.
|
|
|
|
|
Vaclav_ wrote: I just downloaded boost , like to try it, but it does not included format.
I'm not sure what you mean. Are you trying to figure out how to install boost for your OS?
If you have a reasonably recent linux version, you should be able to get boost via the package management system - e.g. apt, yum, etc. But take a look at what version of boost the system is providing, if you're wanting to use boost.process. That was added in v 1.64 which seems to be from April 2017, so that's a recent addition.
|
|
|
|
|
To moderator
I have received e-mail of message flagged as spam.
There is no spam in it, just normal reply.
Funny - how can I receive e-mail of message "pending approval"?
|
|
|
|
|
That just means that the automatic spam filter saw something in the message that may be suspicious. It then holds the message in the pending queue until a member with the relevant authority can review it, and release or reject.
|
|
|
|
|
So this "automation" passes the suspicious message to me ?
It is not OK to view on forum , but OK to "spam" me ?
Yet another half-baked software.
PS
I really want to know WHY you replied to my post?
Do you spend your time surfing every forum here?
Cheers
|
|
|
|
|
It seems that everything you don't understand is somehow taken as a personal assault. The spam filter is designed to prevent the site being flooded with rubbish (which often happens). As it is a piece of automated code, it errs on the side of caution, and sometimes flags innocent messages. Why is that half-baked?
|
|
|
|
|
It seems that everything you don't understand is somehow taken as a personal assault.
Nice example.
Have a nice day.
|
|
|
|
|
There are plenty of resources about ioctl.
All of them refer to "files" which is OK.
What is missing - as far as I am concerned - is actual code where commands and data passed via ioctl function are processed.
It is very common to read " use plain write " to do the hardware manipulation.
Since "what are you trying to do" is often first reply - here is a sample.
Purpose of the code is to output data to I2C hardware:
iResult = write(FileDescriptor,Data,iSize);
Works as expected.
When I get more familiar with ioctl I'll try use I2C ioctl "write macro" instead of "plain" write.
My primary question is - how to find the actual Linux code which "transfers" the write function to sending I2C clock and data. (Mrs Google - via Github - keeps giving me the "files" and not reference to actual Linux source code - perhaps I am asking wrong way - again. )
My secondary is - how to verify that my code actually reads I2C ACK when I send the I2C address.
All I am getting is "number of characters processed", which is fine, but does it "include " verifying the ACK?
Cheers
|
|
|
|
|
|
Yes, that is one of the doc I am using.
I do not see the device / driver dependency.
I thought the "ioctl" sort of bypasses the need for driver giving me access to kernel directly.
I am trying to send generic "write" i2c data.
I am under the impression that once the file descriptor is opened for "device " - in this case "dev/i2c-1" that is all I need to implement the ioctl.
I am not sure how to find the Linux source code for this.
|
|
|
|