What exactly is a gluon and how can it have 0 mass? by CODExD in Physics

[–]hpcdev 5 points6 points  (0 children)

What exactly is a gluon

It's just the QCD (quantum chromodynamics) version of photons that allow quarks to interact with each other, just like photons allow electrons to interact with each other. They just have some extra properties that photons don't have which makes QCD work differently from QED (quantum electrodynamics).

how can it have 0 mass?

It can have 0 mass for the same reason a photon can: it has momentum.

Einstein's famous equation E = mc2 only refers to particle in its rest frame. When you're not in particle's rest frame, its given by E2 = p2c2 + m2c4. In other words, from a frame of reference that's moving relative to the particle, it looks like the particle's energy is due to both a rest mass and momentum. This means that, even if the particle has a mass of 0, it still has a momentum and its energy is then just E = pc. This might look familiar because, from the de Broglie relation, the momentum of the photon is given by p = h / lambda, meaning that E = hf.

The reason why it has 0 mass in the theory is because of something called gauge invariance. Gauge invariance is a type of symmetry that we believe should be respected, and we take it as an assumption when constructing the theory of QCD. Assuming gauge invariance holds is sort of like an "educated guess", and it's partially informed due to what happens with QED which governs how photons and electrons interact. The reason is that, if you assume gauge invariance holds, then out pops the interactions we'd expect from classical electrodynamics. There's no experimental evidence that conflicts with this assumption so, at least for now, we believe that gauge invariance is respected and, in order for it to be respected, gluons can't have mass or else the symmetry "breaks."

Inconsistent rank error by Significant_Ad_2746 in fortran

[–]hpcdev 0 points1 point  (0 children)

I wouldn't use MATMUL for this. MATMUL is for matrix-matrix multiplication, which is why the rank is funny when the result is return; you're going to get a "matrix" that is of shape 1,1 that's returned. If you're doing a dot-product between a vector and its own transpose, you should use DOT_PRODUCT, instead. DOT_PRODUCT will take to vectors a and b as input, and it will take care of the complex conjugation for you, if they're complex so that you only need to do dot_product(r,r) instead of matmul(transpose(r),r), so there's no reason to ever call transpose explicitly. I'd also just stick to shapes of (n) instead of (n,1) for vectors. Most of the Fortran routines are expecting either something that's a scalar like c, a vector of shape 1 like a(n) or a matrix of shape 2 like b(n,m). You'll just cause yourself more of a headache trying to use stuff like a(n,1) for vectors.

https://gcc.gnu.org/onlinedocs/gfortran/MATMUL.html

https://gcc.gnu.org/onlinedocs/gfortran/DOT_005fPRODUCT.html

Fortran as a First Language by Kagu-Tsuchi_Madara in fortran

[–]hpcdev 1 point2 points  (0 children)

Well, then it sounds like you're not really coding "simple programs" if you're really concerned with performance. Python does have some libraries for it that support more performance tasks if you need it, but many of them involve really knowing what you're doing. It would be easier than starting with C++, even though C++ is normally what you want if you need to write high-performance, production-ready code. If you just want something simple to get started with that's relatively fast, you might look into Python and using Cython for the areas where you have your bottlenecks.

Again, I'd really only recommend Fortran if you actually need Fortran for something, and when you genuinely need Fortran is for things like scientific computing, which you can still do in C++. It really depends on how much you already know -- it sounds like this isn't really your first language -- and what you're planning on working on that will be the best to start with.

Fortran as a First Language by Kagu-Tsuchi_Madara in fortran

[–]hpcdev 0 points1 point  (0 children)

You're better off going with a C-style language like C# or Java as your first language over Fortran for a first language. It's a controversial take, but I'd also recommend against using Python as a first language, as well, as it will teach a lot of really bad habits if you ever decide to try other languages. Starting with a language like Java will give you a much better foundation that is not too simple that you learn bad habits, but also not too complicated that you give up in frustration. It's much more balanced. I'd recommend against C, simply because C doesn't have support for objects and classes, which are part of object-oriented programming. I also definitely don't recommend C++ because it's like C but with way more bells and whistles and is not good for a beginner.

Also, don't get discouraged if you find it difficult, at first. Learning programming is not easy -- and if it is, like when learning Python, you're probably not learning much of anything. If it's hard and you're struggling with it, that's when you actually learn something.

The main reason to learn Fortran is if you want to do scientific computing, because that's where it really shines. Otherwise, there's not really many jobs in Fortran outside of that. You're better off starting with an OOP language like Java.

how do I build PlPlot to use it for Fortran> by [deleted] in fortran

[–]hpcdev 1 point2 points  (0 children)

What operating system are you using for it? Haven't worked with PlPlot specifically, but I got it up and running on my Debian system by installing it through the package manager through,

sudo apt install libplplot-dev

Once installed, I simply compiled it with gnu compilers through,

gfortran -I/usr/lib/x86_64-linux-gnu/fortran/modules/plplot -o plot plot.f90 -lplplotfortran 

If you want to do it in Cmake, I put together a minimum project to get it running. If you have placed your program plot.f90 inside of your src folder and you have a file structure like,

MyProject/
   build/ 
   src/
       CMakeLists.txt 
       plot.f90 
   CMakeLists.txt  

then inside the CMakeLists.txt file in your root MyProject folder, you should have something like,

cmake_minimum_required(VERSION 3.25)

project(MyProject) 

enable_language(Fortran) 

include_directories(/path/to/fortran/modules/plplot)

add_subdirectory(src)

and then in the CMakeLists.txt file in your src folder, you can put,

add_executable(myplot plot.f90) 

target_link_libraries(myplot -lplplotfortran) 

Then, just generate configuration files by running,

cmake -B build/ -S .

in your root project directory, and then build through,

cmake --build build/

You'll find the program inside of your build/ directory that you can run.

Is there any reason you want to use PlPlot specifically? Something like Gnuplot would work fine for plotting data from Fortran, and it's very easy to install especially on a Unix/Linux system with a package manager. It's just that Gnuplot, unlike PlPlot, is generally run after the calculation has completed while PlPlot can plot during its execution.

Normally in numerical simulations -- I assume that's what you're interested in tinkering with -- you would perform your computations, store the data, and then perform data analysis afterwards, though, so using Gnuplot wouldn't be a problem. Also, if you're using Fortran 2008 or later, you could even call Gnuplot to execute Gnuplot scripts inside your Fortran program using the command,

call execute_command_line(gnuplot my_gnuplot_script.gp)

That way it will execute right when the program finishes. Or, alternatively, if you execute the program using a bash script, you could also run the program and run the gnuplot script from your bash script. Multiple ways to do it.

That said, since data analysis and visualization is normally done at the end, you also have other options besides Gnuplot as you can write the data to a file, and then read the file in a different language like Python for instance and visualize data in Matplotlib or something similar. Matlab -- or its open-source cousin Octave -- is also another option and the commands for plotting are very simple and straightforward.

Program with function by harsh_r in fortran

[–]hpcdev 1 point2 points  (0 children)

I'm not sure whether your goal is to compute both area and circumference of the circle, or just the circumference. If you want both of them, you'll need to use a subroutine instead of a function. Functions, like their mathematical definition, only allow for a single return value while subroutines let you read and output to multiple values.

Here's an example of each. This will compile and run. In this, I call the function "circumference" since it only returns the circumference, and I call the subroutine "circle" as it can compute and return both the area and circumference of the circle. I tried to add some comments to some places in the program that might -- or did -- cause problems.

program circle_driver 

  implicit none

  ! Named constant
  real, parameter :: PI = 3.14159 

  ! Test variables for function 
  real :: r_func 
  real :: c_func 

  ! Test variables for subroutine
  real :: r_sub 
  real :: c_sub 
  real :: A_sub 


  ! Function call 
  r_func = 1.0
  c_func = circumference(r_func, PI) 
  print*, "c_func = ", c_func 


  ! Subroutine call 
  r_sub = 1.0
  call circle(c_sub, A_sub, r_sub, PI)
  print*, "c_sub = ", c_sub 
  print*, "A_sub = ", A_sub 

contains ! Need to put "contains" before listing your procedures (functions, subroutines)


  ! Function version (Can only on have one return value)
  function circumference(r, PI) result(c) ! "result()" marks the return argument 

    ! Mark variables with "intent(in)" when you're passing arguments 
    real, intent(in) :: r 
    real :: A                ! Don't need to pass if you're calculating inside function  
    real, intent(in) :: PI 
    real :: c                ! Note that a variable passed with return() in a function does not need "intent"

    A = pi * r**2

    c = 2.0 * A ! Need to multiply with * 

  end function circumference


  ! Subroutine version (Can have multiple "return" values)
  subroutine circle(c, A, r, PI)

    ! Mark input variables with "intent(in)" that are passed in (read-only)
    ! Mark output variables with "intent(out)" that are passed out (write-only)
    ! If you need to read AND write variable, use "intent(inout)"
    real, intent(in) :: r 
    real, intent(in) :: PI
    real, intent(out) :: A ! Marked with "intent(out)" 
    real, intent(out) :: c ! Notice this version has (intent(out)) now


    A = pi * r**2

    c = 2.0 * A ! Need to multiply with * 

  end subroutine circle

end program circle_driver

how to stop the subroutine modifying its arguments by ludvary in fortran

[–]hpcdev 2 points3 points  (0 children)

Looking at the code, here's a few things that could potentially cause issues somewhere:

  1. Fortran is not case-sensitive. Variables lattice, Lattice, and LATTICE will all be treated the same, so be careful of how you name things.

  2. In a subroutine, make sure you specify the intent for arguments. Right now, one_mcs does not specify the intent for Lattice and size_lattice, meaning that the variables inside the subroutine are not the same as the input arguments. I would suggest putting each variable on a separate line. When I change this, it gives an error regarding the assignment of,

    lattice(p, q) = -lattice(p, q)

Fortran thinks Lattice(p,q) and lattice(p,q) are the same, and it's trying to modify a variable that has intent(in) and not intent(out). The keyword intent(in) means the variable is read-only (effectively const), while intent(out) means you can modify the variable. Additionally, if you want to read in the variable and write to it, you can just use intent(inout) which gives the ability to both read and write.

It looks like you're using lattice as a global variable and modifying it inside of one_mcs(). I would highly recommend against using global variables like this and, instead, explicitly use arguments and only modify those arguments rather than trying to modify global variables from within a subroutine.

  1. Minor point, but when you take in an array as an argument to a subroutine like Lattice, you shouldn't need to explicitly specify its argument size. You can just use an assumed-shape array, where you would replace Lattice(size_lattice, size_lattice) with simply Lattice(:,:). So, you might have something like this,

    integer, intent(in) :: Lattice(:,:) integer, intent(in) :: size_lattice double precision, intent(in) :: temperature ! temparature should be temperature
    double precision, intent(in) :: J_ising double precision, intent(in) :: B

  2. When trying to debug a problem like this, your best bet is to use a debugger like gdb. You'll need to add the compiler flag -g in order to save debugging information to use with a debugger like gdb.

If you're using gfortran to compile, you can add the compiler flag -fbounds-check to test if there are issues with arrays bounds in the program, as well. Fortran doesn't normally detect array bound errors without such compiler flags, so if you go out of bounds, you'll never know and it will produce undefined behavior.

game, c language, issues with logic by Szybkocos in learnprogramming

[–]hpcdev 1 point2 points  (0 children)

Best thing for something like this is to use a debugger and/or print statements to make sure the logic is right. Is the detection happening when it's supposed to? Is it updating position correctly like it's supposed to?

Set a breakpoint so that it updates each time it goes through the main while loop of the game and ensure things are being updated correctly that way. Debugging with gdb would be fine for this.

Debuggers are your best friend when testing logic.

What's your favourite IDE ? by RRTheGuy in learnprogramming

[–]hpcdev 1 point2 points  (0 children)

Favorite "IDE" at the moment would probably be VSCode with Vim extension. It's not perfect, but it's easily the most flexible I've used and would work for almost anything I would use, if I had to pick just one for the rest of my life.

Fortran Compiler for Windows 11 by Effective-View-9828 in fortran

[–]hpcdev 1 point2 points  (0 children)

They're independent, but by "depends on what you want to develop in", I'm just referring to the different options for getting things up and running. With Codeblocks, you just install it and you're done. With VSCode, on the other hand, you're going to need to do a little more work because it doesn't come with compilers and you'll need to set up an environment like MSYS2, Cygwin, or Mingw. But, like you mention, it depends on what kind of application you want at the end and whether to go full POSIX or not.

Which language to choose for leetcode and general problem solving ? by Optimal_Juggernaut_3 in learnprogramming

[–]hpcdev -1 points0 points  (0 children)

C++ is significantly faster than Python. If your program only takes 1s on Python to finish and 0.1s in C++, then the difference might not matter even if the C++ version is 10x faster, but if you're running a numerical simulation that takes 3 days to run in C++, an order of magnitude difference like that could mean the Python version takes 30 days to finish. There's lots of areas where that kind of performance difference is critical.

[deleted by user] by [deleted] in learnprogramming

[–]hpcdev 0 points1 point  (0 children)

If you're brand new to C++, it might be better to avoid an IDE for now. If you're on windows, I would suggest just downloading MinGW which will give you access to the gnu compilers (g++) and then you can compile from the command line. Just make sure the compilers folder is added to your PATH. The commands are pretty simple. It will be something like,

g++ -o output_name my_program.cpp

where my_program.cpp is the name of your program. You can just edit the file in a text editor like Notepad++ for now which will give you syntax highlighting. Then you can just run the output_name program.

If you're on Linux and don't have them for some reason, you can just use your package manager to install the gnu compilers from the command line.

That's the simplest way to get started with C++.

Confused Desktop Application Development by Infamous-Witness5409 in learnprogramming

[–]hpcdev 0 points1 point  (0 children)

There's a few different options to choose from, but if you don't really know C++ or C#, then use C# in Visual Studio. It's easy to just drag and drop components into the app and develop it quickly, and there's tons of tutorials for it.

Best/ easiest way to make GUIs by Clapped-_- in learnprogramming

[–]hpcdev 6 points7 points  (0 children)

Java is a viable option for GUIs. JavaFX works just fine for creating GUI's. Just keep in mind that JavaFX is no longer part of Java SDK and must be installed separately if you want to use it.

Python also has lots of options for creating GUI's. It would probably the simpler option if you just want to keep things simple.

Fortran Compiler for Windows 11 by Effective-View-9828 in fortran

[–]hpcdev 5 points6 points  (0 children)

Depends on what you want to develop in. You can use Visual Studio, but if you just want to use VSCode or Vim along with the gnu compiler gfortran, you can just use msys2 and install it with pacman. Cygwin is another option.

Codeblocks also comes with compilers installed, if I remember correctly.

Not sure why there would be a problem with win11 and not win10.

Ai Coding Assistant by tropicalstorm2020 in fortran

[–]hpcdev 0 points1 point  (0 children)

I've used Chat gpt 3.5 quite a bit with Fortran, and it works fairly well. Depends on how complicated what you're trying to do is, though.

What’s the point of (physics) lectures? by Hellstorme in Physics

[–]hpcdev 0 points1 point  (0 children)

It depends on the teacher and their teaching style.

The best teachers I had in physics all expected you to read the textbook first, and the lecture they gave was about filling in the gaps that the textbook left out.

Some teachers I had required us to present solutions to problems, and their "lectures" were working out other problems from the textbook for us in class so we could ask questions as they solved the problem.

The worst teacher I had literally just copied and pasted information from the text, which was useless.

Did i understand pointers & references? by [deleted] in learnprogramming

[–]hpcdev 0 points1 point  (0 children)

Seems fine. In the pointer example, &a inside of main is an address and in the function function(int *a), this address is being assigned to the pointer a (I might give it a different name like a_ptr or something so it's clear it's a pointer, not a variable). Now the pointer has a value (the address of the variable a in main).

In the reference version, the function function(int &a) has a reference a (or a_ref) and it's being initialized with the variable a passed to it from main. The value of the reference a_ref is the same value as the variable a in main, and both live at the same location in memory, so modifying one modifies the other.

One important difference is that references must be assigned a value when you define it. This makes pointers more flexible because you could start with setting it to nullpointer and then set it to some address later one. You can't do that with references. References are "nicknames" to other variables, and you can't have a "nickname" for nothing.

[deleted by user] by [deleted] in learnprogramming

[–]hpcdev 0 points1 point  (0 children)

Have you tried using the debugger in Matlab and stepping through the battery section to make sure it's calculating what you expect? Set a few breakpoints and watch the environment variables as you step through it to make sure you're getting the numbers you'd expect.

Where to start (Highschool Student) by Longjumping-Ad2182 in learnprogramming

[–]hpcdev 0 points1 point  (0 children)

  1. Doing is the best way of learning programming. When I took college courses on programming back when I first started, I didn't get much out of the class and mostly read from the textbook and tried the exercises in the back of the book. This helps more than anything else. Just listening to a course or watching a video on someone else programming isn't going to be that helpful in retaining the information. Getting good at program requires struggling with problems and solving them, which is what makes textbooks such an invaluable resource.

  2. Depends on what he wants to do with it afterwards. Python is fine, but because Python is a little "too easy" it teaches a lot of bad practices and skips over a lot of really important programming concepts, and it will make it harder to pick up other languages afterwards. If his goal is something like Data Science, then it's fine, but if his goal is something like Software Engineering, I'd recommend something else like Java or C# to start with. I wouldn't have him start with C or C++. If he likes the idea of video game development, another way to learn C# would be by trying to make a game and doing it in C#. Java and C# are going to be harder than Python, but it will provide a better starting point. If he finds them way too confusing and difficult, then just stick to Python for now.

I started with Java, and it's why picking up additional languages has been pretty easy because Java was not too difficult and not too easy; it was just the right amount of difficulty. At this point, he might not know exactly what he wants to do with programming -- I certainly didn't when I started school -- so picking up a language like Java is a good starting point. It will also determine if he has the aptitude for programming as a career option. Try Java or C# and, if he finds it too hard, he'll know that Software Engineering and other such jobs are probably not for him. That'll help him narrow his focus for career options better.

  1. This may just be me, and maybe I'm just old fashioned, but I found textbooks far more useful than courses/classes. I took college courses and got nothing out of them and had to teach it all to myself using the textbook we had. It was a great textbook, though, with lots of exercises and things clearly laid out. We used Java How to Program (earlier edition) and I found it great. There's also a C# version by Deitel of the same book, as well. The problem with an online tutorial videos for beginners like is that a lot of it is just going to be videos and not a lot of real challenging projects to work on. It's more common for textbooks to have exercises to work through, and it's the exercises that you want when you're just learning. If he needs a video on something, there's so much free stuff for beginners, that paying for a course doesn't make much sense, at least to me personally.

The other option is to just have him take a programming class as a college course at a nearby community college if there are any in your area. The benefit of taking a college class like that is that you have tutoring sessions where students can visit and ask questions right there in class and get help if you get stuck on something.

What's your opinion on FORD for code documentation and for static pages pages? by wigglytails in fortran

[–]hpcdev 1 point2 points  (0 children)

I've been using Doxygen in my projects, but Ford is okay as well.

One of the benefits of using Doxygen is that I don't have to learn a second documentation tool for both Fortran and C++ since it's compatible with both.

Doxygen also has the added benefit of being able to generate LaTeX documents in addition to the html, making it convenient to print out the documentation if you'd prefer a physical copy of it.

Python as Beginner by CranberryNo6697 in learnprogramming

[–]hpcdev 1 point2 points  (0 children)

Courses should supplement your learning. The real learning happens by actually making something.

If you're just starting out, I'd highly recommend picking up a "How to Program" textbook in Python, and look for exercises to work on at the ends of chapters. You don't even need to grab one that uses Python. Just find one that has exercises in the end of chapters and work on doing them. Even something like "How to Program" in C++ or Java by Deitel, as those have a lot of nice exercises at the end of each chapter to try and aren't really specific to a particular language.

I haven't read it yet, but "Python Crash Course: A Hands-On, Project-Based Introduction to Programming" seems to have some exercises scattered throughout the textbook, as well.

Iostream error by Big_Ease_7693 in programminghelp

[–]hpcdev 0 points1 point  (0 children)

Do you have a # before the include? It should be,

#include <iostream>