|
I'm currently working on a lattice Boltzmann code (D3Q27) employing MPI for parallelization. I've implemented MPI 3D topology for communication, and my code snippet handles communication as follows, I also have the same structure for the communication between front-back and up-down.
void Simulation::Communicate(int iter) {
int tag_xp = 0;
int tag_xm = 1;
int tag_yp = 2;
int tag_ym = 3;
int tag_zp = 4;
int tag_zm = 5;
MPI_Status status;
if (SubDomain_.my_right_ != MPI_PROC_NULL) {
std::vector<double> send_data;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
if (SubDomain_.lattice_[SubDomain_.my_Nx_ - 2][j][k] == nullptr) {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(0.0);
}
}
else {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(SubDomain_.lattice_[SubDomain_.my_Nx_ - 2][j][k]->m_distributions[dir]);
}
}
}
}
std::vector<double> recv_data(send_data.size());
MPI_Sendrecv(send_data.data(), send_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xp,
recv_data.data(), recv_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xm,
MPI_COMM_WORLD, &status);
int index = 0;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
for (int dir = 0; dir < _nLatNodes; dir++) {
SubDomain_.lattice_[SubDomain_.my_Nx_ - 1][j][k]->m_distributions[dir] = recv_data[index];
index++;
}
}
}
}
if (SubDomain_.my_left_ != MPI_PROC_NULL) {
std::vector<double> send_data;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
if (SubDomain_.lattice_[1][j][k] == nullptr) {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(0.0);
}
}
else {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(SubDomain_.lattice_[1][j][k]->m_distributions[dir]);
}
}
}
}
std::vector<double> recv_data(send_data.size());
MPI_Sendrecv(send_data.data(), send_data.size(), MPI_DOUBLE, SubDomain_.my_left_, tag_xm,
recv_data.data(), recv_data.size(), MPI_DOUBLE, SubDomain_.my_left_, tag_xp,
MPI_COMM_WORLD, &status);
int index = 0;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
for (int dir = 0; dir < _nLatNodes; dir++) {
SubDomain_.lattice_[0][j][k]->m_distributions[dir] = recv_data[index];
index++;
}
}
}
}
}
While I can verify that communication occurs correctly by printing sent and received data, upon visualization, it appears that the data might not be transferring to neighboring processors as expected, despite not being zeroed out (as previously confirmed through printing). After each iteration, I visualize the velocity components obtained via the Lattice Boltzmann Method (LBM). My observation reveals that the fluid dynamics are solely resolved within the processor featuring the inlet boundary condition, while all other processors exhibit a velocity of zero. This suggests that data transfer to neighboring processors might not be occurring as expected.
I have a couple of concerns:
Could data corruption arise from blocking communication? Is diagonal communication necessary? My understanding is that if communication in the normal directions (x, y, and z) is established, diagonal communication implicitly occurs. Additionally, I'm uncertain about the order of communication. Do all communications happen simultaneously, or is it sequential (e.g., right and left, then front and back, then up and down)? If they're not simultaneous, would diagonal communication be required?
I also have a confusion in receiver processor id. for example
MPI_Sendrecv(send_data.data(), send_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xp, recv_data.data(), recv_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xm, MPI_COMM_WORLD, &status); should it be SubDomain_.myrank_, instead of SubDomain_.my_right_ in receive part?
I'd appreciate any insights to clarify these points of confusion. Thank you!
|
|
|
|
|
Use code tags when you post code.
The context of your questions is not clear.
There is theory and there is practice (implementation). To which do your questions refer?
Are you asking if your code is right? And only that?
Are you asking if your theory is right? And only that?
If the second then the code doesn't help.
If the first then you should provide some specifics about which part of the code you think has a problem.
If you are mixing the two then I would suggest that you rethink what it is that you actually need to ask.
I suspect also that at least for the theory you need to run on hardware that tests this. Not clear to me how your code insures that the hardware is even being used. That however might both be because you didn't use code tags and because I didn't look that closely at the code.
|
|
|
|
|
I have "include" (cloned) a full project from "github".
It is missing ONE header file, hence ,it won't compile.
I have found another resource which contains the missing file.
This resource appears to be a "stand alone" header
and it does not give much explanation how to use it.
I am asking for suggestion
how to "merge" these resources,
basically how to
change the working clone "dbus/files"
to
"stand alone " "dbus/files"
Simple
include both does not work
Here is my current setup
UNDER construction
<pre>
this contains the missing header BUT NO OTHER CODE !
INCLUDEPATH += "/home/nov25-1/Downloads/nobus-master/include/dbus-1.0/dbus"
# temp removed contains usable code, but missing ONE header file
INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/simplebluez/"
#INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/"
#INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/simpledbus/advanced/"
#INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/"
///usr/include/core/dbus/dbus.h
#INCLUDEPATH += "/usr/include/"
#INCLUDEPATH += "/usr/include/dbus-1.0/"
# links to first dbus.h "missing" file
#INCLUDEPATH += "/usr/lib64/dbus-1.0/include/"
#INCLUDEPATH += "/home/nov25-1/Downloads/nobus-master/include/dbus-1.0/dbus"
# INCLUDEPATH += "/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11 _FEB26/A_BT_LIBRARY/CCC_SOURCE/BT_no_bus/nobus-master/include/dbus-1.0"
#//dding -I/usr/lib64/dbus-1.0/include/ in c
#include <dbus/dbus-arch-deps.h>
INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/"
INCLUDE_DIRECTORIES("../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/simplebluez")
#INCLUDEPATH = c:/msdev/include d:/stl/include
PS.
If it is unclear what I am asking for
please ask for clarification.
|
|
|
|
|
You can add any header files to your project repository, or in another location using the INCLUDEPATH variable as you have shown. But I am not sure what you mean by "a "stand alone" header", so yes, your question is not clear. Maybe if you showed the relevant code plus any error messages, it will become clearer.
|
|
|
|
|
Salvatore Terress wrote: I have "include" (cloned) a full project from "github"
Presumably you mean a single repo.
Salvatore Terress wrote: how to "merge" these resources,
Repo A has the code.
Repo B has the include file.
Copy the file from B and put it into A.
You do nothing at all with B after that.
Modify whatever you need to in A so the include file, in A, is used correctly. Compile and test A.
|
|
|
|
|
That is what I thought would work...
I may have to change A to be read / write...
I'll let you know the outcome...
Thanks
|
|
|
|
|
|
which github ?
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
A SimpleBluetooth - full code
B nodbus dbus header only
both have dbus as a "wrapper' folder.
I am busy trying to keep the separate but in my own directory stricture.
So I have not actually compare the real headers.
I won't be surprised if the foundation is "bluez
library.
There are too many "clones" of this undocumented source...
seems a waste of talent to keep reinventing " bluez"...
|
|
|
|
|
Hi guys, I'm trying to understand the mechanism behind the Paige-Tarjan algorithm. I searched a lot on the internet but I found only papers with analytical explanations, but I would lite to understand pratically how it works, with an example, an exercise or something else.
I already downloaded the bispy repository on git but I don't understand how it works pratically, which are the steps that lead me to say that this is the result
for an easy example, with this graph:
0 -> 1,2
1 -> 3,4
2 -> 5,6
3,4,5,6 -> null
I can't understand which are the steps that results in:
[(1, 2), (3, 4, 5, 6), (0,)]
I hope someone can explain me this. Thank you all.
|
|
|
|
|
link to the git ?
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
|
Extracting the Points from a CRgn Object - C / C++ / MFC ...
|
|
|
|
|
|
I've an MFC app. When the mouse hovers over a spot, I want a small popup window to appear displaying helpful info. It goes away when the mouse moves etc. How is this done? Need some clues. Thanks.
|
|
|
|
|
It depends on what is in the spot that the mouse is hovering over. Take a look at sme of the following links: mfc tooltip - Google Search[^].
|
|
|
|
|
This is my current resource:
https://www.ibm.com/docs/en/zos/2.1.0?topic=line-using-redirection-symbols
unfortunately I am not sure WHERE the redirection belongs
in my system call parameters.
Here is my TEST code
QFile *resultFile;
system(" echo q | sudo -S hcitool cc --role=c 98:D3:31:F8:29:33 > resultFile");
system(" echo q | sudo -S hcitool info 98:D3:31:F8:39:33 > resultFile");
return;
and the TEST debug result
[sudo] password for nov25-1: Can't create connection: Input/output error
[sudo] password for nov25-1:
neither one provides data output to "resultFile".
Please note that the first "system" call attempts to "connect" and fails ,hence
would not have any data to redirect anyway. Expected with "no
connection " behavior.( Used to test compiler /linker. )
I am asking for help placing the ">resultFile" into system call.
|
|
|
|
|
I don't know what's the difference between the two commands. I don't know what hcitool does, but I don't think that matters.
What the command(s) do, is to pass the string "q" as stdin to sudo . If "q" is the user password, that's fine because sudo expects to read the user password. On my machine I tried:
echo xxxxxx | sudo -S ps -A > results and that works fine. I get the output of ps in the results file ("xxxxxx" is the user "password").
Now how useful or portable such an approach is, is another question.
- Do you plan to have user's password embedded in your code? What if you change your password? would you recompile the code or what?
- Wouldn't it be simpler to just accept that your code has to be run as root?
- Maybe you can set hcitool to be run with sudo without a password. Take a look at Sudoers Manual[^]:
Quote: PASSWD and NOPASSWD
By default, sudo requires that a user authenticate before running a command. This behavior can be modified via the NOPASSWD tag. Like a Runas_Spec, the NOPASSWD tag sets a default for the commands that follow it in the Cmnd_Spec_List. Conversely, the PASSWD tag can be used to reverse things. For example:
ray rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm
would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm as root on the machine “rushmore” without authenticating himself. If we only want ray to be able to run /bin/kill without a password the entry would be:
ray rushmore = NOPASSWD: /bin/kill, PASSWD: /bin/ls, /usr/bin/lprm
Mircea
|
|
|
|
|
Here is my test code :
system( "echo q | sudo -S ps -A "); return;
and partial output to console
sudo] password for nov25-1: PID TTY TIME CMD
1 ? 00:00:07 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
5 ? 00:00:00 slub_flushwq
6 ? 00:00:00 netns
8 ? 00:00:00 kworker/0:0H-events_highpri
11 ? 00:00:00 mm_percpu_wq
12 ? 00:00:00 rcu_tasks_kthread
13 ? 00:00:00 rcu_tasks_rude_kthread
no output with "resultFile"
hence
same outcome as with original code
PS
ONLY , so far , the "hcitool info" require password AND current system call passing it works as expected.
|
|
|
|
|
This works for me:
#include <stdlib.h>
#include <stdio.h>
int main ()
{
int ret;
ret = system ("echo xxxxxx | sudo -S ps -A >results");
printf ("ret=%d\n", ret);
return 0;
} The output goes to "results" file and ret is 0.
Environment: Ubuntu 22.04LTS freshly installed yesterday.
Compiler: gcc 11.1.0
Mircea
modified 19-Feb-24 21:48pm.
|
|
|
|
|
Just to make sure - how is your results file declared /defined?
I am getting correct return value but no data anywhere - no console or file.
|
|
|
|
|
It doesn’t exist before running the program. It is created by the command. If you want to read it, you should open it after the command has finished.
Mircea
|
|
|
|
|
Kindly allow me to "write review".
The OP question was answered.
by placing the redirection as last option of the system call.
Ir was verified by passing by complier / linker and function
returning success ( 0 ).
However, as coded there is no "passed to " function seen in debugger,
( since it is part of the options ?)
and
there is no practical value of the "passed to " function if it cannot be read.
hence there is an extension to my OP
how to read the contents of the "passed to" function ?
after that question extension is answered there will be another
modification
how to "pipe" ca;; result to the console and redirect it to a file SAME time ?
I sincerely appreciate your contribution to resolve this.
|
|
|
|
|
|
I'm not sure I understand your question. Something might be "lost in translation".
You cannot send results to file and console "at the same time". What you can do is send them to the console right after you sent them to the file. For instance:
ps -A >results && cat results
If what you want is to read the results in your program and process them somehow, you could do something like:
#include <stdlib.h>
#include <stdio.h>
int main ()
{
int ret;
char line[256];
ret = system ("echo xxxxxx | sudo -S ps -A >results");
FILE *f = fopen("results", "r");
while (!feof(f)) {
fgets (line, sizeof(line), f);
puts(line);
}
fclose(f);
return 0;
} I didn't compile this code but should be rather OK.
If you explain better what you want to do maybe I can answer more to the point.
Mircea
|
|
|
|
|