Problem of plotting picture and video in Linux HPC

Click For Summary
SUMMARY

The discussion addresses issues encountered when running a Matlab program on a Linux High Performance Computer (HPC) that successfully operates on Windows OS using R2014a. Users face warnings regarding display settings and errors related to the 'getframe' function, indicating that graphics cannot be displayed. The solution involves setting the DISPLAY environment variable and utilizing X-forwarding when logging in via SSH to enable graphical output.

PREREQUISITES
  • Understanding of Matlab R2014a programming
  • Familiarity with Linux HPC environments
  • Knowledge of environment variables in Linux
  • Experience with SSH and X-forwarding techniques
NEXT STEPS
  • Learn how to configure DISPLAY environment variables in Linux
  • Research X11 forwarding with SSH for remote graphical applications
  • Explore Matlab's 'VideoWriter' and 'getframe' functions for video creation
  • Investigate alternative methods for rendering graphics in headless environments
USEFUL FOR

Matlab developers, researchers using Linux HPC for simulations, and anyone needing to visualize data without a graphical interface.

kelvin490
Gold Member
Messages
227
Reaction score
3
I have a Matlab program that reads data file and then create avi. files and tiff pictures. It runs without problem in window OS using R2014a but cannot run in a Linux high performance computer(HPC).

When the Matlab in Linux is started there are two warnings:
Warning: No display specified. You will not be able to display graphics on the screen.
Warning: No window system found. Java option 'Desktop' ignored.

When I run my program there are two error messages:
Error using getframe (line 53)
getframe requires a valid figure window.

Error in Density_3Dplot (line 93)
writeVideo(vid, getframe(gcf)); %get the picture and put in the avi file with
the handle "vid"

When I run the program in window, pictures are displayed one by one and the command getframe and writeVideo are used to put the pictures into the avi file. However when I run it in a node in HPC nothing can be displayed. How can I modify my program so that it can be run in a system without display? Thanks a lot.

I put my code here for your reference:
clear; close all; clc;%clear all previous data
fig = figure(1);%These two lines maximize the figure dialogue
set(fig,'Units','normalized','outerPosition',[0,0,1,1]);
fig_color='w'; fig_colordef='white';
cMap=jet(256);%set the colomap using the "jet" scale
%The following defines an alternative colormap called cMap2 (from white to red)Nmap=64;
cMin2 =[111];
cMax2 =[100];
cMap2 = zeros(Nmap,3);for i =1:Nmap;
cMap2(i,:)= cMin2*(Nmap- i)/(Nmap-1)+ cMax2*(i -1)/(Nmap-1);end

% cMap(1,:)=[111];
faceAlpha1=1;
faceAlpha2=0.65;
edgeColor1='none';
edgeColor2='none';NumBoxX=100;%box number in x direction
NumBoxY=100;%box number in y directionNumBoxZ=5;%box number in z directionFirstFile=0;%the number of the first file to be readFileInterval=400;%the number of intervals between filesLastFile=2000;%the number of the last file to be read34010ValCol=4;%indicate which column is used as value for plotting e.g. the 4th column is dis. density

[MinDis,MaxDis]=Find_MaxMin(FirstFile,FileInterval,LastFile,ValCol);%Call the function to find min and max density,used to define the range of colorbar

set(gcf,'Renderer','zbuffer');%eliminate unnecessary background and prevent stationary video -Important!
vid =VideoWriter('Evolution.avi');%Create a avi file
vid.Quality=100;
vid.FrameRate=15;
open(vid);%Open the avi file so that films can be put into it later on

for ii=FirstFile:FileInterval:LastFile%Thisfor loop controls the sequential reading of data files
ns = numel(num2str(ii));%Findout the number of digits of the number of file
switch ns %The following converts the file name so that they can be used in fopen belowcase1%it's for one digit, 1,2 etc.
filename = ['rho ' num2str(ii) '.dat'];
case 2 %it's for two digits,10,20 etc.
filename =['rho ' num2str(ii)'.dat'];case3%it's for three digits, 100,110 etc.
filename = ['rho ' num2str(ii) '.dat'];
case 4 %it's for4 digits
filename =['rho ' num2str(ii)'.dat'];case5%it's for 5 digits
filename = ['rho ' num2str(ii) '.dat'];
end

fid = fopen(filename,'r');
datacell = textscan(fid, '%f%f%f%f%f%f%f%f'); %There are 8 columns to be read so there are 8 %f
fclose(fid);

all_data = cell2mat(datacell); %converted into a matrix containing all the dis. density info. for every simulation cell

M=zeros(NumBoxX,NumBoxY,1); %create a matrix of 50x50x1,representing array of simulation cells M=zeros(NumBoxX,NumBoxY,NumBoxZ);
% % the following loops assign the dislocation density from all_data to M
for i=1:NumBoxX
for j=1:NumBoxY
for k=1:1 %for k=1:NumBoxZ Only the middle plate is shown
num=3+NumBoxZ*(j-1)+NumBoxZ*NumBoxY*(i-1);%num=k+NumBoxZ*(j-1)+NumBoxZ*NumBoxY*(i-1);
% if all_data(num,ValCol)<1e13
% all_data(num,ValCol)=0;
% end
M(i,j,k)=all_data(num,ValCol); %the ValCol column of all_data is dislocation density
end
end
end

indPatch=1:numel(M);
[F,V,C]=ind2patch(indPatch,M,'v'); %Call the function ind2patch in order to plot 3D cube with color
title('adfdadasfdasf','fontsize',20);%set title \sigma_{xx}
xlabel('y','fontsize',15);ylabel('x','fontsize',15); zlabel('z','fontsize',20); hold on;
set(get(gca,'xlabel'),'Position',[50 -10 30]); %set position of axis label
set(get(gca,'ylabel'),'Position',[-3 50 -15]);
% set(get(gca,'zlabel'),'Position',[64 190 -60]);
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'EdgeColor','k','FaceAlpha',0.5);
axis equal; view(90,-90); axis tight; axis vis3d; grid off;
colormap(cMap);
caxis([MinDis MaxDis]); %set the range of the colorbar MinDis MaxDis %caxis([min(M(:)) max(M(:))]); %range of the colorbar according to one file only
cb = colorbar; % create the colorbar
set(get(cb,'title'),'string','dfdfdfd(m^{-2})','fontsize',20); % label the colorbar Stress (MPa)

lbpos = get(cb,'title'); % get the handle of the colorbar title
set(lbpos,'units','normalized','position',[0,1.06]);
MyAxes=gca;
set(MyAxes,'Units','Normalized','position',[0.05,0.1,0.8,0.8]);

writeVideo(vid, getframe(gcf)); %get the picture and put in the avi file with the handle "vid"

title('aaaaa','fontsize',10);%set title \sigma_{xx}
set(get(cb,'title'),'string','aaaaa(m^{-2})','fontsize',10); % label the colorbar Stress (MPa)
picturename = ['aaaaa' num2str(ii) ]; % set the name of the picture with number
print(fig,picturename,'-dtiff');%save the picture in choosen format '-djpeg' | '-dpng' | '-dtiff' | '-dpdf' | '-deps' | ...end

close(vid); %close the avi file after putting all the films into it
 
Last edited:
Physics news on Phys.org
It might be that you need to set your DISPLAY environment variable,

http://nl.mathworks.com/matlabcentral/newsreader/view_thread/165074

Basically you do something like:
export DISPLAY=192.168.1.1:0

where 192.168.1.1 is the ip-address of the hpc machine.

If you log in remotely using ssh, you also need to use X-forwarding.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 2 ·
Replies
2
Views
3K