Professional Documents
Culture Documents
HPC-FINAL
HPC-FINAL
HPC-FINAL
Experiment: - 1
➢ Machine Learning: -
• Training models: Colab's free access to powerful GPUs and TPUs makes it ideal for
training computationally intensive machine learning models. You can experiment with
different algorithms and hyperparameters easily without needing a powerful local machine.
• Developing and testing ML applications: Colab allows you to build and test your machine
learning applications right within the browser. This makes it a quick and convenient way to
iterate and debug your code.
➢ Data Science: -
• Data analysis and visualization: Colab offers various libraries for data analysis and
visualization, including NumPy, Pandas, and Matplotlib. This allows you to explore and
analyze your data sets without installing any software.
• Data cleaning and processing: Colab provides tools for cleaning and preprocessing your
data before analysis, making it ready for model training or further exploration.
➢ Education: -
• Interactive tutorials and notebooks: Colab enables educators to create interactive tutorials
and notebooks that combine code, text, and visualizations. This makes learning more
engaging and interactive for students.
• Teaching programming: Colab can be used to teach programming languages like Python,
especially for beginners, as it requires no setup and provides a user-friendly interface.
• Sharing educational resources: Educators can share their Colab notebooks with other
instructors and students, facilitating the dissemination of educational resources.
1|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
➢ General use: -
• Running scripts and code snippets: Colab can be used to run simple scripts and code
snippets without needing a local development environment. • Exploring libraries and
frameworks: You can use Colab to explore new libraries and frameworks without installing
them on your local machine.
• Developing web applications: Colab supports various web development libraries and
frameworks, allowing you to build and experiment with web applications directly in the
browser
• Interactive environment:
1. Colab allows you to combine code, text, images, and more in a single document.
2. This makes it easy to experiment and explore ideas.
3. You can also easily share your notebooks with others, making Colab a great tool for
collaboration.
• Easy to share:
1. You can easily share your Colab notebooks with others.
2. This makes it a great tool for collaboration.
3. You can also share your notebooks publicly, so that others can see your work and learn
from it.
• Preemptible VMs:
1. Colab offers preemptible VMs
2. which are virtual machines that can be stopped at any time to make room for other users.
3. This is a great way to save money if you're only running short-lived jobs.
2|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
• Customizable runtime:
1. You can customize the runtime environment for your Colab notebook.
2. This means that you can install specific libraries and dependencies that you need for your
project.
• Offline support:
1. You can use Colab offline by saving your notebook to your local machine.
2. This is a great way to work on your project even if you don't have an internet
connection.
• Version control:
1. Colab integrates with Google Drive
2. which provides version control for your notebooks.
3. This means that you can easily track changes to your notebooks and revert to previous
versions if necessary.
• Automatic backups:
1. Colab automatically backs up your notebooks to Google Drive.
2. This means that you don't have to worry about losing your work if your computer crashes
or you accidentally delete your notebook.
Python program
Code: -
g = int(input("ENTER A NUMBER TO CHECK : "))
a=0
k=0
for i in range(1,a+1):
if(g%i==0):
print(i)
k = k+1
if(k==2):
print("IT IS A PRIME NUMBER ")
else:
print("IT IS NOT A PRIME NUMBER")
OUTPUT:
3|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
C – PROGRAM
CODE:
#include<stdio.h>
int main()
{
float a, b,average;
printf("Enter the firstnumber: ");
scanf("%f", &a)
printf("Enter the second number: ");
scanf("%f", &b);
average = (a + b) / 2;
printf("The average of %.2f and %.2f is %.2f\n", a, b, average);
return 0;
}
OUTPUT:
4|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Experiment -2
Linux Commands: -
1. PWD:
• pwd - Print Working Directory.
• The pwd command is used to display the location of the current working directory.
• The pwd showing the full path.
Syntax: pwd
Output:
2. LS:
• Ls - List
• The ls command is used to display a list of content of a directory.
• Lists files and directories in the specified directory.
• Common options include -l for detailed listing and -a for showing hidden files.
Syntax: ls [options] [directory] or ls
Output:
5|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
3. CD:
• cd - Change Directory.
• The cd command is used to change the current directory.
• The Use cd to go to the home directory.
• cd .. to move up one level.
Syntax: cd [directory
Output:
4. MKDIR:
• mkdir - Make Directory
• Creates a new directory with the specified name.
• The mkdir command is used to create a new directory under any directory
Output:
6|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
5. RMDIR:
• rmdir - remove Directory
• The rmdir command is used to delete a directory.
• In other words, you can use this command to delete a particular directory
6. TOUCH:
• The touch command is just like a mkdir command.
• The touch command is used to create empty files.
• We can create multiple empty files by executing it once
7|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
7. CAT:
• The cat command is a multi-purpose utility tool in the Linux system.
• It can be used to create a file, display content of the file, copy the content of one
file to another file, and more.
• This is much quicker than opening the file in an editor.
8. RM:
• rm - remove
• The rm command is used to remove a file.
• it discards all the items alone without the owner’s permission.
• Maintain certified backup of all the critical documents at all times
Syntax: rm [options] <filename/directory>
Output:
8|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
9. CP:
• cp - copy
• The cp command is used to copy a file or directory.
• Specifies the source file or directory to be copied.
• Specifies the destination where the source will be copied.
10.MV:
• mv - move
• The mv command is used to move a file or a directory form one location to
another location.
• The base file name is retained when you relocate a file or directory to another guide
• The mv command reorganizes the folder or transfers the directory from one directory
to another
9|Page
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
11.HEAD:
• The head command is used to display the content of a file
• It displays the first 5 lines of a file.
• The head command prints the top N numbers of data from the provided input.
• Data from each file is introduced by its document if only one filename is given.
12.TAIL:
• The tail command is similar to the head command.
• It The difference between both commands is that it displays the last ten lines of the
file content.
• is useful for reading the error message.
Syntax: tail [options] <filename>
Output:
10 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
13.TAC:
• The tac command is the reverse of cat command, as its name specified.
• It displays the file content in reverse order (from the last line).
• Attach non-empty lines before a line with a separator.
• Treat the separator string as a regular expression.
Syntax: tac [options] <filename>
Output:
14.DATE:
• The date command will show the Week, Month, Day and Time.
• The date command is versatile and can be used in scripts
• The command line to generate timestamps, automate tasks based on dates
• For various other date-related operations.
Syntax: date
Output:
11 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
15.CAL:
• The cal command is used to display a simple calendar. It shows a calendar for the
current month or a specified month and year.
• If you run the cal command without any options, it will display the calendar for
the current month.
• The cal command provides a quick and simple way to view calendars in the terminal.
• For more advanced calendar operations, you might consider using other tools or
graphical calendar applications
Syntax: cal
Output:
16.ECHO:
• The cal command is used to display a simple calendar. It shows a calendar for
the current month or a specified month and year.
• If you run the cal command without any options, it will display the calendar for
the current month.
Syntax: echo
Output:
12 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
17.CHMOD:
• The chmod command lets you change the mode of a file (permissions) quickly. It
has a lot of options available with it.
• The basic permissions a file can have are:
1. r (read)
2. w (write)
3. x (execute)
• One of the most common use cases for chmod is to make a file executable by the
user. To do this, type chmod and the flag +x, followed by the file you want to
modify permissions on:
18.UNAME:
• the uname command is used to check the complete OS information of the system.
• Check out the command and the output below.
• The command ‘uname‘ displays the information about the system
Syntax: uname
Output:
13 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
19.WC:
• The wc command can accept zero or more input FILE names. If no FILE is
specified, or when FILE is -, wc will read the standard input. A word is a string of
characters delimited by a space, tab, or newline.
• In it’s simplest form when used without any options, the wc command will print
four columns, the number of lines, words, byte counts and the name of the file for
each file passed as an argument. When using the standard input the fourth column
(filename) is not
Syntax: wc OPTION
Output:
20.WHOAMI:
• You can use the whoami command in shell scripts to check the user’s name running the
Script.
• Here is an example using an if statement to compare the user’s name running the script
with a given string.
• whoami does not accept arguments. If you pass an argument, the command prints an error
message:
Syntax: whoami
Output:
14 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
21.SLEEP:
• Searches for files in a directory with the specified name.
• The find command searches for files in a directory hierarchy based on a
regex expression.
• To use it, follow the syntax below
Syntax: sleep 5
Output:
22. I:
• The default editor that comes with the UNIX operating system is called vi
(visual editor).
• Using vi editor, we can edit an existing file or create a new file from scratch.
• we can also use this editor to just read a text file. The advanced version of the vi
editor is the vim editor
Syntax: vi[file_name]
Output:
15 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
23. ID:
• The id command is used to display the user ID (UID) and group ID (GID).
• The id command in Linux is used to display user and group information for
the current user or a specified username or user ID.
• -u, --user: Display only the user ID.
• -g, --group: Display only the effective group ID
Syntax: id
Output:
24.EXIT:
• The exit command terminates a script, just as in a C program. It can also return a
value, which is available to the script's parent process.
• Issuing the exit command at the shell prompt will cause the shell to exit.
• Common aliases for exit include "bye", "logout", and "lo".Every command
returns an exit status
Syntax: exit
Output:
16 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
25.CLEAR:
• clear is a standard Unix computer operating system command that is used to clear the
terminal screen.
• This command will ignore any command-line parameters that may be present. Also,
the clear command doesn’t take any argument and it is almost similar to cls command
on a number of other Operating Systems
• This command first looks for a terminal type in the environment and after that, it
figures out the terminfo database for how to clear the screen
Syntax: clear
Output:
26.TIME:
• The time command is used to display the time to execute a command.
• The time command in Linux is a useful tool for measuring the execution time of
a command or script.
• It provides detailed information about the real, user, and system time consumed by the
executed command
Syntax: time
Output:
17 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
27. DF:
• The df command is used to display the disk space used in the file system.
• It displays the output as in the number of used blocks, available blocks, and
the mounted directory.
• The displayed disk space usage may not be entirely accurate in some cases, especially
if file system metadata is not updated promptly
Syntax: df
Output:
28.PING:
• PING (Packet Internet Groper) command is used to check the network
connectivity between host and server/host.
• This command takes as input the IP address or the URL and sends a data packet
to the specified address with the message “PING” and get a response from the
server/host this time is recorded which is called latency.
• Fast ping low latency means faster connection. Ping uses ICMP(Internet Control
Message Protocol) to send an ICMP echo message to the specified host if that host is
available then it sends ICMP reply message. Ping is generally measured in
millisecond every modern operating system has this ping pre-installed
Output:
18 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
29.HISTORY:
• The history command in Linux is a built-in shell tool that maintains a record
of commands executed in the current terminal session.
• It allows users to view, search, and reuse previously executed commands, saving
time and effort.
• Lists previously run commands
Syntax: history
Output:
30.PS:
• The output includes information about the shell (bash) and the process running in this shell
(ps, the command that you typed):
• The four columns are labeled PID, TTY, TIME, and CMD..
• PID- The process ID. Usually, when running the ps command, the most important
information the user is looking for is the process PID. Knowing the PID allows you to
kill a malfunctioning process .
• TTY - The name of the controlling terminal for the process.
• TIME - The cumulative CPU time of the process, shown in minutes and seconds.
• CMD - The name of the command that was used to start the process
Syntax: ps
Output:
19 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory Code:
203105430
B. Tech – 3rd Year 6th Semester
20 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory Code:
203105430
B. Tech – 3rd Year 6th Semester
21 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
PRACTICAL -4
AIM: Write a program on an unloaded cluster for several different numbers of nodes and
record the time taken in each case Draw a graph ofexecution time against the number of nodes
Define Requirements:
Select Hardware:
Networking:
Cluster Architecture:
Decide on the cluster architecture, such as symmetric or asymmetric, and the arrangement of
nodes.Consider the use of a master node for managing the cluster and coordinating tasks.
Choose a suitable operating system for the cluster (common choices include Linux
distributions tailored for HPC, such as CentOS, Ubuntu, or specialized HPC-centric OS).
Install necessary software tools, libraries, and middleware for parallel processing and job
scheduling (e.g., MPI for message passing, Slurm or Torque for job scheduling).
22 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
File System:
Implement a high-performance parallel file system that can handle the I/O demands of your
applications.Consider distributed or parallel file systems like Lustre or GPFS.
Cluster Management:
Install cluster management software for monitoring, resource allocation, and job scheduling.
Popular choices include OpenHPC, Bright Cluster Manager, or custom configurations using
tools like Puppet or Ansible.
Ensure adequate power and cooling infrastructure to support the cluster, especially
considering the high power consumption of HPC systems.
Testing:
Perform thorough testing to validate the functionality and performance of the HPC
cluster.Test parallel processing capabilities, network communication, and overall system
stability.
Optimization:
Documentation:
Create comprehensive documentation for the cluster setup, configuration, and maintenance
procedures.
Training:
Provide training for administrators and users on how to effectively use and manage the HPC
cluster.
Scaling:
Plan for future scalability by designing the cluster with expansion capabilities, enabling the
addition of more nodes as needed.
23 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Computer Hardware:
- Provision at least three servers for primary, worker, and client nodes.
Software:
- HPC frameworks like Hadoop offer fault-tolerance and automatic system redirection
Facilities:
- Networking gear such as NICs and switches are crucial for the cluster
24 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
import time
X=[[1,2],[1,4],[1,0],[4,2],[4,0],[4,4],[4,5],[0,2],[5,5
]]
#Nilesh=6B5
nodes = [1,2,3,4,5]
time_taken=[]
for n in nodes:
start_time=time.time()
kmeans=KMeans(n_clusters=n)
kmeans.fit(X)
end_time=time.time()
time_taken.append(end_time - start_time)
plt.plot(nodes, time_taken)
plt.xlabel('Number of nodes')
plt.ylabel('Time Taken')
plt.title('Time taken vs Number of Nodes')
plt.show
OUTPUT
25 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
26 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
EXPERIMENT -5
What are profilers: Profiling is the process of measuring the execution time of
a program and identifying where the program spends most of its time. The gprof
tool is typically associated with the GNU Compiler Collection (GCC) and is
available on many Unix-like operating systems.
What is Gprof: gprof is a profiling tool that is commonly used in the context of
software development, particularly with programs written in languages like C
and C++. The tool is part of the GNU Compiler Collection (GCC) and is
available on many Unix-like operating systems.
The primary purpose of gprof is to provide insights into the execution time of a
program, helping developers identify performance bottlenecks and optimize
their code
Features: gprof is a profiling tool that provides developers with insights into
the runtime behavior and performance characteristics of their programs. Here
are some of the key features and information that gprof can provide:
Flat Profile:
Summary of the time spent in each function.
Percentage of the total program execution time spent in each function.
Number of calls and self-time (exclusive time spent in the function) for each
function.
Call Graph:
A graphical representation of the function call relationships.
Displays which functions call other functions and the percentage of time spent
in each.
Execution Count:
Information about how many times each function was called during the
program's execution.
Time Distribution:
Shows the percentage of total program execution time spent in various
functions.
Helps identify functions that consume a significant portion of the runtime.
27 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Command-Line Options:
gprof provides various command-line options to customize the output and
analysis. For example, specifying the executable to analyze, setting the sorting
criteria for the output, and more.
‘It's important to note that while gprof is a helpful tool for basic profiling, it
may have some limitations, and for more sophisticated profiling needs,
developers might explore other profiling tools or techniques. Additionally,
some modern development environments and IDEs provide integrated
profiling tools with graphical interfaces for a more user-friendly experience’
28 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Simple code:
C-Program
%%writefile add.c
// C Program to demonstrate Decimal to Hexadecimal
// Conversion using the format specifier
#include <stdio.h>
int main()
{
int decimalNumber = 45;
29 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
30 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Complex code:
C-PROGRAM
%%writefile add.c
#include <stdio.h>
int main() {
long long sum = 0; // Using long long to handle large sums
int limit = 100000000; // 1 crore
return 0;
}
31 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
32 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
Experiment No: 6
AIM :- Use Intel V-Tune Performance Analyzerfor Profiling.
Intel V-Tune Profiler:
Intel offers a performance profiling tool called Intel VTune Profiler. VTune Profiler is part of the Intel
oneAPI toolkit, and it is used for performance analysis and tuning of applications. Please note that there
may have beenupdates or changes since my last knowledge update.
Use Intel VTune Profiler to analyze local and remote targetsystemsfromWindows*, macOS*, and
Linux*hosts. Improve application and system performance through these operations:
• Understand where and how your application can benefit fromavailable hardware resources.
• Whether your application is CPU or GPU bound and how effectively it ofloadscode to the GPU
Download Intel VTune Profiler to your system through one of these ways:
33 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
2. Build your application with symbol information and in Release mode with all optimizations
enabled. For detailed information on compilersettings, see the VTune Profiler online user guide.
You can also use the matrix sample application available in \VTune\Samples\matrix. You can see
correspondingsample results in \VTune\Projects\sample (matrix).
34 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
The Performance Snapshot analysis type is a good starting point for your profiling experience with Intel®
VTune™ Profiler. This analysis gives you a general overview of your application performance with
recommendations forareas to focus.
1. In the Launch Application section, browse to the location of yourapplication executable file.
2. Click Start to run Performance Snapshot on your application. This analysis presents a general
35 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
36 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
Experiment No: 7
AIM :- Analyze the code using Nvidia-Profilers.
Nvidia Profilers:
NVIDIA profiling tools enable us to understand and optimize the performance of our CUDA, OpenACC or OpenMP
applications. The Visual Profiler is a graphical profiling tool that displays a timeline of your application’s CPU and
GPU activity, and that includes an automated analysis engine to identify optimization opportunities. The nvprof
profiling tool enables you to collect and view profiling data from the command-line.
1. Visual:
The NVIDIA Visual Profiler allows you to visualize and optimize the performance of your application. The
Visual Profiler displays a timeline of your application’s activity on both the CPU and GPU so that you can identify
opportunities for performance improvement. In addition, the Visual Profiler will analyze your application to detect
potential performance bottlenecks and direct you on how to take action to eliminate or reduce those bottlenecks.
2. Nvprof:
The nvprof profiling tool enables you to collect and view profiling data from the command-line. nvprof
enables the collection of a timeline of CUDA-related activities on both CPU and GPU, including kernel execution,
memory transfers, memory set and CUDA API calls and events or metrics for CUDA kernels. Profiling options are
provided to nvprof through command-line options. Profiling results are displayed in the console after the profiling
data is collected, and may also be saved for later viewing by either nvprof or the Visual Profiler.
3. Remote Profiling:
Remote profiling is the process of collecting profile data from a remote system that is different than the
hostsystem at which that profile data will be viewed and analyzed. There are two ways to perform remote
profiling. You can profile your remote application directly from an nsight orthe Visual Profiler. Or you can use
nvprof to collect the profile data on the remote system and then use nvvp on the host system to view and analyze
the data.
4. MPI Profiling:
nvprof has a built-in option thatsupports two MPI implementations - OpenMPI and MPICH. If you have
either of these installed on your system, you can use the –annotate-mpi option and specify your installed MPI
implementation.
5. MPS Profiling:
You can collect profiling data for a CUDA application using Multi-Process Service (MPS) with nvprof and
then view the timeline by importing the data in the Visual Profiler.
Code:
%%writefile addi.cu
#include global void add(int a, int b, int *c) {
*c = a + b;
}
int main() {
int a,b,c;
37 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
a=3; b=4;
cudaMalloc((void**)&dev_c, sizeof(int));
add<<>>(a,b,dev_c);
cudaMemcpy(&c, dev_c,sizeof(int), cudaMemcpyDeviceToHost);
printf("%d + %d is %d\n", a, b, c);
cudaFree(dev_c);
return 0;
}
Output :
38 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
PRACTICAL – 8
2203031249007 39 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
2203031249007 40 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: high performance computing Lab
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
2203031249007 41 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Experiment -9
Objective: - Write a simple CUDA program to print "Hello World!"
What is CUDA:
• CUDA stands for Compute Unified Device Architecture.
• It is an extension of C/C++ programming.
• CUDA is a programming language that uses the Graphical Processing Unit (GPU).
• It is a parallel computing platform and an API (Application Programming Interface)
model, CUDA was developed by NVIDIA.
• This allows computations to be performed in parallel while providing well-formed speed.
• Using CUDA, one can harness the power of the Nvidia GPU to perform common computing
tasks, such as processing matrices and other linear algebra operations, rather than simply
performing graphical calculations.
Features of CUDA:
CUDA (Compute Unified Device Architecture) from NVIDIA offers several features that make it a
powerful tool for parallel computing using GPUs. Here are some key features of CUDA:
2203031249007
43 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
Step2: - Select the runtime in Google Colab (Change runtime type to T4GPU)
2203031249007
44 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
OUTPUT: -
• Run the CUDA program
OUTPUT: -
2203031249007
46 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Subject Code: 203105430
B. Tech – 3rd Year 6th Semester
2203031249007
47 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
Experiment No: 10
%%writefile addi.cu
#include<stdio.h>
global void add(int a, int b, int *c)
{
*c = a + b;
}
int main()
{
int a,b,c;
int *dev_c;
a=3;
b=4;
cudaMalloc((void**)&dev_c, sizeof(int));
add<<<1,1>>>(a,b,dev_c);
cudaMemcpy(&c, dev_c,sizeof(int), cudaMemcpyDeviceToHost);
printf("%d + %d is %d\n", a, b, c);
cudaFree(dev_c);
return 0;
}
OUTPUT:
48 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
%%writefile addition.cu
#include <stdio.h>
#include <cuda_runtime.h>
int main() {
int n = 10;
int *a, *b, *c;
int *d_a, *d_b, *d_c;
int size = n * sizeof(int);
a = (int *)malloc(size);
b = (int *)malloc(size);
c = (int *)malloc(size);
cudaFree(d_a);
49 | P a g e
2203031249007
FACULTY OF ENGINEERING & TECHNOLOGY
Subject Name: High Performance Computing Laboratory
Code: 203105430
B. Tech – 3rd Year 6th Semester
cudaFree(d_c);
free(a);
free(b);
free(c);
return 0;
}
OUTPUT :
50 | P a g e
2203031249007