From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 77A0A385842B for ; Tue, 9 Jan 2024 18:31:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77A0A385842B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 77A0A385842B Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1704825087; cv=pass; b=moz/LYD2cvAniw4FkxFW8x5AbyYAEi390JzR6tq5eb8vDpkzO2uiIliM0mLXyDtZr0qEc4cGTMhwzci5KM9yLfd4qb635+BqH2XWWD5947VB6ps19X23N+qhKh1pPkX6YkqvIWVvL7i2ZB5bDgDJ9o773KfOG+gayIx3G6jnWhY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1704825087; c=relaxed/simple; bh=ql3wwr2YI1UDmTjiTlVWbbFHyBgnjNeSAOtA2sL7MHc=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=wr+0iaYWHooJh7Spjl75RgdpH2jI125iWaSxJL3Ag6autwPfpuwV68VW9ShK/s3w1E4A7os6Nm15b/lf5V2PaYKlk23ajjvpARdzTfWef2Ff+VyGtjBVpqND5Ymn8iN70CKQi636wPpsw5L57QZbD7a8+z7CwkKy3mj/I7O863E= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 409IEvYo008033 for ; Tue, 9 Jan 2024 18:31:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=ZeGN0YCOHqepuOhIwOW79eE11DHtjr9OSmdtVSgAsRU=; b=eaeRnvjlsT9xEbBY/+l4IcTHpX6AHiUWXot2iDTYQrclfp0BxtObkFaMNm6+0UY08a9m +tjV5MJEDc3bvm+tsnNvM/zZHke5hBf/dEc6JF0JD0zBL3V3SEAEKW6XbwAj8OrWCYFq 0qZVo+o98W4ADeHiBsAMlF1aJgh3DTEc3ZZ/QZRrLHwMTL4gpnFzMH3/dUc76S5bRGWt 0Pjuirin7WLQfBPEa4tVkvA4Ym+fir5MaEkN2eQ8sBXz1KgphJUgiYO1EPGi9uBWs7Dz WTVZsFufxLA/ujsbe0LDXzk1GNzWF/OMdLWaPWcjnsVz2nNACxBSutlqbRg8zlmy1Twk fA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vh9r98bhx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 09 Jan 2024 18:31:19 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 409I5gt6030111 for ; Tue, 9 Jan 2024 18:31:18 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutme4jk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 09 Jan 2024 18:31:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G3yzT835cltIUqjAvgWbLkw6Lwn5s2P9bQh0xP4elsgEQ82j1328XZZUmstwI81JZLrI+ixlIcKu6bOB1eiv0gkLHXVPy5jyogt1uXzDcf2c7OgtcCUBhrUb7psINqN/qnOfftnVyuqTNk6pY0TRQFZu9bo0HsAMeR3CwZj8KVlsNhux0H4tFy5j7hT4FbeQWOnlx/60GqilZIeOkHdFgQd8bWguU8e9UKhL1+vmfG/1E5t9WRc+6mA/PPCvUnBHPADl8CBZm2xixAybQrpAsTS6JnuEBpWTDa67RUHFJARlij04L2q8JRFiytQ0CdElxzSikRyAkyCdjk8MrpNe5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZeGN0YCOHqepuOhIwOW79eE11DHtjr9OSmdtVSgAsRU=; b=IRjRCnqtC6MXal4pje8K3Q2OSxWqQQYzhBgkxzPzu50A7HXc7fkEtNsGyl1TZiaz9LTsMGq7d/HGTM4sUUHaA5uMQihAhn2FXZ1ixp36hA4XE4TEqKOKMj8TZr4DxBIzSSTTobzVSoi4S2OPJHx+66ES01xcV3WvX2LRvtYEBxDhVsxT+RqUWDiz+CogkSKucWykvODiXaJgpdIJtoizkfrDVXrQpQE1/fpUvl7rdbgFqxCsGFZLGN/Tlzpf9wLzRQLGHrQWbmq41BbGQ4hTizIOj3/GUj2lTRiCM7AH2QR23jIPSLT3KGVQhSZSRzZg0XTzig0OswaiMSRCQchd3g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZeGN0YCOHqepuOhIwOW79eE11DHtjr9OSmdtVSgAsRU=; b=PCK+MMUmmnYHQHGvKtUaS+5poxFXavRd5Iwq78NDxec7/BjAoJqlHZWs94jLPalPbm7rE3ahGRb0p/ae42Ycxu5/rSAlAu9s/ME0mUhLEolkxuF2lO24VJTee1ZGbIIMb4uzit/+hO6XPqVzEFidj8r+uPetOsUOpgs0LHA4c90= Received: from SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10) by MN2PR10MB4336.namprd10.prod.outlook.com (2603:10b6:208:15f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.23; Tue, 9 Jan 2024 18:31:14 +0000 Received: from SA2PR10MB4636.namprd10.prod.outlook.com ([fe80::5b9b:a8a:21f6:a505]) by SA2PR10MB4636.namprd10.prod.outlook.com ([fe80::5b9b:a8a:21f6:a505%3]) with mapi id 15.20.7159.020; Tue, 9 Jan 2024 18:31:14 +0000 From: vladimir.mezentsev@oracle.com To: binutils@sourceware.org Cc: Vladimir Mezentsev Subject: [PATCH] gprofng: add an examples directory Date: Tue, 9 Jan 2024 10:31:08 -0800 Message-Id: <20240109183108.1044974-1-vladimir.mezentsev@oracle.com> X-Mailer: git-send-email 2.31.1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-ClientProxiedBy: PH0PR07CA0056.namprd07.prod.outlook.com (2603:10b6:510:e::31) To SA2PR10MB4636.namprd10.prod.outlook.com (2603:10b6:806:11e::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PR10MB4636:EE_|MN2PR10MB4336:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ca94fe3-d490-41a4-84b4-08dc11412930 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2t+fliFYmmbO4oRyTLJOnFws3m39A1o7JPRvsJo3r+lDR0/1PoGl8fuONllQM2Bf2xJdGYZ8NteX/Yjj5ZnjT7tFlK6dsXh8dtTSk1ditUf74zzDrEKoZRvawK0TYJMMrx16Y9aiLYETqe0SFD1zWSeV0RLEjekvu+p4tGTDgHXzGyvnKFqsN0x/qDwNBrqYcM3xXx/yozURNotaHsnhhK/QIgK7gaTsku2s8a0mdmzQFWEc5l/W4iZQ/nXvY4mfC+GMXueu7KBZVW2Fu4tVrgEhhsmy18iTKQr3fo+FCLapgCoa/wRoAa4g4TWccalORq+0lkXB/1YogIc83I4UJVkzlr0WK4KPrS082GhhWTwk4vxUF4uY/EW+5uKa3tO83DN4zayjeBZzj/tR8x+YZqhY7IrniObFFEN8gor4+fXSSJ1hmwZDfdE93CzrDmzwc6LAo2sFtx9Ozq1X5yZh6Qf9lBHQjOnuN57RkdItlRU1jJ30YBcgXdEYB5mBvkkBDZs5r57wN7awdWJ7fJFwO2Nkes6XbaHTmD4idiXDQHTAc5KE8fWePr7pBejmRxKNSFk4zk92Bov3gxuXHFtjAJCY2qngBQu0Lg8Aa4BaG46P3ahV+mI+XmaBCLL/NUvw4t0VBuZWJ39XKliWJvRmMw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA2PR10MB4636.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(366004)(346002)(376002)(136003)(39860400002)(230922051799003)(230173577357003)(230273577357003)(451199024)(1800799012)(64100799003)(186009)(2906002)(38100700002)(30864003)(5660300002)(86362001)(41300700001)(2616005)(316002)(36756003)(8676002)(8936002)(6486002)(9686003)(6512007)(107886003)(66946007)(66556008)(6916009)(66476007)(1076003)(478600001)(6506007)(83380400001)(6666004)(4326008)(2004002)(579004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?PU+sFBfc4x+fe3aidgy6KoSg10XAZhEj0IYxfz5m3IG52Zp4fVgbtXh8bMpO?= =?us-ascii?Q?+c6YIHGcgy4uJ+MVNTLG5WPjaZk+q8kKpEnKRSYc9EV8RfqpBDpOym7QSVJZ?= =?us-ascii?Q?dX6DZX38x8Cp8G3Z2ax25UuZo3kI+mmAFAkwyCQvVi3IOYMQVfCulSjjeOMD?= =?us-ascii?Q?qsAnC5QuEJvPu2GtcAGYAIE+q1aDQOQQ+ZBD0/AHoyyaIqZQyLB4mnS/cWbm?= =?us-ascii?Q?FBz45ZHY1inkOMRyv/Q2PO28U1i9fSSOWJQOouP3mO7EUimgtjoeLxN/VxC/?= =?us-ascii?Q?6MLnP95YdgddtB0d57+CohY0jVKVOD6QDZw8u3aJNx/pMQhm81nHcsU6AvpR?= =?us-ascii?Q?4t0TmjhOCA82dGjA3jKHRGeMg4VppegOd7+ocAjEtKKEeUyxpDV9aFxApBvv?= =?us-ascii?Q?iXRq6TofrO9bFR7UYocAcoGazXKmOEwMZnSqAjzolprajurmaSz0S0XJvGLD?= =?us-ascii?Q?Dr0RTE5YevAcLptEIwGq1kFTaHEK5gBDQJb7H0T6XYxu4c7SR2nRqIQ7ZFKD?= =?us-ascii?Q?eMluSGeobf4+i58hHMiEDk5+ddzh0u8P2/rdhTlyDortkC5PYgiOOALsGSNv?= =?us-ascii?Q?fI0irUvxjmQe9TBwdaQpPD1c8KgukdCyYH2+fhubDlCmAt0ToHqNDXrTURQN?= =?us-ascii?Q?yp8Ed0ZwFQaIAGhg0F0CBenMJU63RqcTpVlxr5K2aaNsBwcDRErhxdtShW52?= =?us-ascii?Q?AXWOhfL1iiRMijrThOddmCugNusUyXraH/g6vpG5XvrmoHW4vDFRJnMREle1?= =?us-ascii?Q?Ygy5CRRnKbAO4UBTnENuI038f7wQNZs02QndCY3CGOpPEjqQhB5g16QWkUO8?= =?us-ascii?Q?ToyxqPm0EfswH+2yXq23jv+mSecCx19Zi4talunQ4E/I9flTrV1aASY4sPWL?= =?us-ascii?Q?ebToTZbDe4vZbIWZ3ybm08rvGFWzi5of+lti765SZhpxuJLZS2S+HFnN5j00?= =?us-ascii?Q?7eBg4C5TyYdNp8PwZBwttxMTvjQzhLcON6Fxz3XOQiRSu7I9VuOrsaNL/VBz?= =?us-ascii?Q?Pw6OCQNuVc5GgSn+zUMwIcHcTLK3rT48W0Y03QlywFQw8i3WdvZBYhbA8eAT?= =?us-ascii?Q?VkW2cFzqqCnP7L9MvMedNIy5wjmBv63WF3s9NbLKX/o+TPx7Lq7my99JvKob?= =?us-ascii?Q?RVEtqurg0PCFGlFYxx1T1uc1Y5Nd+tphYOB/ulkpjBPVJrWAvJVK4aq+UVvX?= =?us-ascii?Q?RdWMIXqO/Yw98iJHqN7JPKjwH6cb8XqYO0gYIwjMZXIgpOgTAHnKoNDfUeQF?= =?us-ascii?Q?tu9ZRogBgTyK311R7s3uHRlJILokrjDC5Kl9ChiPgUyCQERiMG13iZFiBHCQ?= =?us-ascii?Q?T7WGBnQiVb4U1Ua0ZDnmfog6WC/xI7eW5HQM9G4rffC6kljKJnhEqIow392M?= =?us-ascii?Q?gI5v3kPKLIU6t+wT0ZPvMCYmgsS1VVJT2sIfIxzkywgN7VqO10M4UeTHnw1W?= =?us-ascii?Q?4LnBRCXo8cGuF0Ve2Xh8tC1PwR3KKI1fH7fUwz/JVJX3s+WUHO12zG6XTYSf?= =?us-ascii?Q?tiKYs05/7wwSe438EOkMmN2xiwFyE0l3HmcRxPiwNooekHYhVMr+k5JC/u5v?= =?us-ascii?Q?UbpD9BGDB6qAp+8u9X5vx5kN4DMSASPs75F6VX74txa9XPTYYk3Fd1As+re3?= =?us-ascii?Q?s2k7jzcv4qzcUDWFvJkwUub5nqU1R3ncc8OtnmhdVz/o?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: hYU1rOJn5JOy75v7XDBQJH3KpieOXVlsT0HMvjHr5OIH+NneE+dC6ubTh6MSHzdV35+zDopCSVsf729ltre68IhZ7Bi+y/9lmzIqaoiXJ8eSRHy1Fr4DJr7Y+7sJxdFWBBSOofTSd4kg1WAhInNxVYJlI/JQIsB5MJK5mDJFahqSSsvtaP4eqDXt5ipkN98y8LwYcv3TnwaeVoslGSy+jqtdQz6dnqhO+vZrEhp/vdWTaG4m82lym2tZ5fU94dqsO98huRG48Vwi1CCE24zv1ObP6RpsGjlR0+cos80ZpsRJ/8NQWu2iA/N7v5TWLssZs8S7Y9RzSc4dsJhm6P4DwRrpjucKgQ483Ur0vLBCffP4IpmG70LBzyWRiR6i3fcb4V8zFEsw+VWv1r6HnBePB4ShCyJtBKPgQZdMCYhSW0NyXxlBTDXANCidYzDpO5quA3AsUOFPykq1g2FXvxbAJqDjQ2T/de8R7m3qvCMljXlE7bGKqHIdmfNoJlt6DBTR2nRbxLJfjK9+6+ZQ1SVwVb7m6cf1PMGVVOL7uQAG5jVqYR81ZJLY0R8t0NNNrcwXVCQUlg2rLE20S5ztNqsDeCA+o/r8alIw01hWItqOp58= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ca94fe3-d490-41a4-84b4-08dc11412930 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4636.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jan 2024 18:31:14.3308 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AFk6Sfp4wADb+QHGjPfWp28IMoOwOlBhmtLnEArjGXm1w3AJTK8Gz4xhgPTrBRDm5G8HGeBxSrr5oknq0SP0k1ti56okHCRFN8MDDnbG/ro= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR10MB4336 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-09_09,2024-01-09_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401090149 X-Proofpoint-ORIG-GUID: 3mPOE2HV3bE00bctv6OfI6V4hzQJm9pn X-Proofpoint-GUID: 3mPOE2HV3bE00bctv6OfI6V4hzQJm9pn X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_ASCII_DIVIDERS,KAM_SHORT,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Vladimir Mezentsev This directory contains example programs for the user to experiment with. Initially there is one application written in C. The plan is to include more examples, also in other langauges, over time. In addition to the sources and a make file, a sample script how to make a profile is included. There is also a README.md file. gprofng/ChangeLog 2024-01-08 Ruud van der Pas * examples: Top level directory. * examples/mxv-pthreads: Example program written in C. --- gprofng/examples/mxv-pthreads/README.md | 158 ++++++++ .../mxv-pthreads/experiments/profile.sh | 79 ++++ gprofng/examples/mxv-pthreads/src/Makefile | 70 ++++ gprofng/examples/mxv-pthreads/src/main.c | 374 ++++++++++++++++++ .../examples/mxv-pthreads/src/manage_data.c | 148 +++++++ gprofng/examples/mxv-pthreads/src/mxv.c | 78 ++++ gprofng/examples/mxv-pthreads/src/mydefs.h | 117 ++++++ gprofng/examples/mxv-pthreads/src/workload.c | 91 +++++ 8 files changed, 1115 insertions(+) create mode 100644 gprofng/examples/mxv-pthreads/README.md create mode 100755 gprofng/examples/mxv-pthreads/experiments/profile.sh create mode 100644 gprofng/examples/mxv-pthreads/src/Makefile create mode 100644 gprofng/examples/mxv-pthreads/src/main.c create mode 100644 gprofng/examples/mxv-pthreads/src/manage_data.c create mode 100644 gprofng/examples/mxv-pthreads/src/mxv.c create mode 100644 gprofng/examples/mxv-pthreads/src/mydefs.h create mode 100644 gprofng/examples/mxv-pthreads/src/workload.c diff --git a/gprofng/examples/mxv-pthreads/README.md b/gprofng/examples/mxv= -pthreads/README.md new file mode 100644 index 00000000000..28450a6e2a8 --- /dev/null +++ b/gprofng/examples/mxv-pthreads/README.md @@ -0,0 +1,158 @@ +# README for the matrix-vector multiplication demo code=0D +=0D +## Synopsis=0D +=0D +This program implements the multiplication of a matrix and a vector. It i= s=0D +written in C and has been parallelized using the Pthreads parallel program= ming=0D +model. Each thread gets assigned a contiguous set of rows of the matrix t= o=0D +work on and the results are stored in the output vector.=0D +=0D +The code initializes the data, executes the matrix-vector multiplication, = and=0D +checks the correctness of the results. In case of an error, a message to t= his=0D +extent is printed and the program aborts. Otherwise it prints a one line=0D +message on the screen.=0D +=0D +## About this code=0D +=0D +This is a standalone code, not a library. It is meant as a simple example = to=0D +experiment with gprofng.=0D +=0D +## Directory structure=0D +=0D +There are four directories:=0D +=0D +1. `bindir` - after the build, it contains the executable.=0D +=0D +2. `experiments` - after the installation, it contains the executable and= =0D +also has an example profiling script called `profile.sh`.=0D +=0D +3. `objects` - after the build, it contains the object files.=0D +=0D +4. `src` - contains the source code and the make file to build, install,=0D +and check correct functioning of the executable.=0D +=0D +## Code internals=0D +=0D +This is the main execution flow:=0D +=0D +* Parse the user options.=0D +* Compute the internal settings for the algorithm.=0D +* Initialize the data and compute the reference results needed for the cor= rectness=0D +check.=0D +* Create and execute the threads. Each thread performs the matrix-vector=0D +multiplication on a pre-determined set of rows.=0D +* Verify the results are correct.=0D +* Print statistics and release the allocated memory.=0D +=0D +## Installation=0D +=0D +The Makefile in the `src` subdirectory can be used to build, install and c= heck the=0D +code.=0D +=0D +Use `make` at the command line to (re)build the executable called `mxv-pth= reads`. It will be=0D +stored in the directory `bindir`:=0D +=0D +```=0D +$ make=0D +gcc -o ../objects/main.o -c -g -O -Wall -Werror=3Dundef -Wstrict-prototype= s main.c=0D +gcc -o ../objects/manage_data.o -c -g -O -Wall -Werror=3Dundef -Wstrict-pr= ototypes manage_data.c=0D +gcc -o ../objects/workload.o -c -g -O -Wall -Werror=3Dundef -Wstrict-proto= types workload.c=0D +gcc -o ../objects/mxv.o -c -g -O -Wall -Werror=3Dundef -Wstrict-prototypes= mxv.c=0D +gcc -o ../bindir/mxv-pthreads ../objects/main.o ../objects/manage_data.o = ../objects/workload.o ../objects/mxv.o -lm -lpthread=0D +ldd ../bindir/mxv-pthreads=0D + linux-vdso.so.1 (0x0000ffff9ea8b000)=0D + libm.so.6 =3D> /lib64/libm.so.6 (0x0000ffff9e9ad000)=0D + libc.so.6 =3D> /lib64/libc.so.6 (0x0000ffff9e7ff000)=0D + /lib/ld-linux-aarch64.so.1 (0x0000ffff9ea4e000)=0D +$=0D +```=0D +The `make install` command installs the executable in directory `experimen= ts`.=0D +=0D +```=0D +$ make install=0D +Installed mxv-pthreads in ../experiments=0D +$=0D +```=0D +The `make check` command may be used to verify the program works as expect= ed:=0D +=0D +```=0D +$ make check=0D +Running mxv-pthreads in ../experiments=0D +mxv: error check passed - rows =3D 1000 columns =3D 1500 threads =3D 2=0D +$=0D +```=0D +The `make clean` comand removes the object files from the `objects` direct= ory=0D +and the executable from the `bindir` directory.=0D +=0D +The `make veryclean` command implies `make clean`, but also removes the=0D +executable from directory `experiments`.=0D +=0D +## Usage=0D +=0D +The code takes several options, but all have a default value. If the code = is=0D +executed without any options, these defaults will be used. To get an over= view of=0D +all the options supported, and the defaults, use the `-h` option:=0D +=0D +```=0D +$ ./mxv-pthreads -h=0D +Usage: ./mxv-pthreads [-m ] [-n ] [-t & LOG=0D +```=0D +=0D +## Additional comments=0D +=0D +* The reason that compiler based inlining is disabled is to make the call = tree=0D +look more interesting. For the same reason, the core multiplication funct= ion=0D +`mxv_core` has inlining disabled through the `void __attribute__ ((noinlin= e))`=0D +attribute. Of course you're free to change this. It certainly does not aff= ect=0D +the workings of the code.=0D +=0D +* This distribution includes a script called `profile.sh`. It is in the=0D +`experiments` directory and meant as an example for (new) users of gprofng= .=0D +It can be used to produce profiles at the command line. It is also suitabl= e=0D +as a starting point to develop your own profiling script(s).=0D diff --git a/gprofng/examples/mxv-pthreads/experiments/profile.sh b/gprofng= /examples/mxv-pthreads/experiments/profile.sh new file mode 100755 index 00000000000..f8812a29abf --- /dev/null +++ b/gprofng/examples/mxv-pthreads/experiments/profile.sh @@ -0,0 +1,79 @@ +# +# Copyright (C) 2021-2023 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING3. If not see +# . +# +#-------------------------------------------------------------------------= ----- +# This script demonstrates how to use gprofng. +# +# After the experiment data has been generated, several views into the data +# are shown. +#-------------------------------------------------------------------------= ----- + +#-------------------------------------------------------------------------= ----- +# Define the executable, algorithm parameters and gprofng settings. +#-------------------------------------------------------------------------= ----- +exe=3D../experiments/mxv-pthreads +rows=3D4000 +columns=3D2000 +threads=3D2 +exp_directory=3Dexperiment.$threads.thr.er + +#-------------------------------------------------------------------------= ----- +# Check if gprofng has been installed and can be executed. +#-------------------------------------------------------------------------= ----- +which gprofng > /dev/null 2>&1 +if (test $? -eq 0) then + echo "" + echo "Version information of the gprofng release used:" + echo "" + gprofng --version + echo "" +else + echo "Error: gprofng cannot be found - if it was installed, check your p= ath" + exit +fi + +#-------------------------------------------------------------------------= ----- +# Check if the executable is present. +#-------------------------------------------------------------------------= ----- +if (! test -x $exe) then + echo "Error: executable $exe not found - check the make install command" + exit +fi + +echo "-------------- Collect the experiment data -------------------------= ----" +gprofng collect app -O $exp_directory $exe -m $rows -n $columns -t $threads + +#-------------------------------------------------------------------------= ----- +# Make sure that the collect experiment succeeded and created an experiment +# directory with the performance data. +#-------------------------------------------------------------------------= ----- +if (! test -d $exp_directory) then + echo "Error: experiment directory $exp_directory not found" + exit +fi + +echo "-------------- Show the function overview -------------------------= ----" +gprofng display text -functions $exp_directory + +echo "-------------- Show the function overview limit to the top 5 -------= ----" +gprofng display text -limit 5 -functions $exp_directory + +echo "-------------- Show the source listing of mxv_core -----------------= ----" +gprofng display text -metrics e.totalcpu -source mxv_core $exp_directory + +echo "-------------- Show the disassembly listing of mxv_core ------------= ----" +gprofng display text -metrics e.totalcpu -disasm mxv_core $exp_directory diff --git a/gprofng/examples/mxv-pthreads/src/Makefile b/gprofng/examples/= mxv-pthreads/src/Makefile new file mode 100644 index 00000000000..ef1c55aa77e --- /dev/null +++ b/gprofng/examples/mxv-pthreads/src/Makefile @@ -0,0 +1,70 @@ +#=0D +# Copyright (C) 2021-2023 Free Software Foundation, Inc.=0D +#=0D +# This file is free software; you can redistribute it and/or modify=0D +# it under the terms of the GNU General Public License as published by=0D +# the Free Software Foundation; either version 3 of the License, or=0D +# (at your option) any later version.=0D +#=0D +# This program is distributed in the hope that it will be useful,=0D +# but WITHOUT ANY WARRANTY; without even the implied warranty of=0D +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0D +# GNU General Public License for more details.=0D +#=0D +# You should have received a copy of the GNU General Public License=0D +# along with this program; see the file COPYING3. If not see=0D +# .=0D +=0D +CC =3D gcc=0D +WARNINGS =3D -Wall -Werror=3Dundef -Wstrict-prototypes=0D +OPT =3D -g -O=0D +CFLAGS =3D $(OPT) $(WARNINGS)=0D +LDFLAGS =3D=0D +LIBS =3D -lm -lpthread=0D +OBJDIR =3D ../objects=0D +BINDIR =3D ../bindir=0D +EXPDIR =3D ../experiments=0D +=0D +EXE =3D mxv-pthreads=0D +OBJECTS =3D $(OBJDIR)/main.o $(OBJDIR)/manage_data.o $(OBJDIR)/workload.o = $(OBJDIR)/mxv.o=0D +=0D +default: $(BINDIR)/$(EXE)=0D +=0D +$(BINDIR)/$(EXE): $(OBJECTS)=0D + @mkdir -p $(BINDIR)=0D + $(CC) -o $(BINDIR)/$(EXE) $(LDFLAGS) $(OBJECTS) $(LIBS)=0D + ldd $(BINDIR)/$(EXE)=0D +=0D +$(OBJDIR)/main.o: main.c=0D + @mkdir -p $(OBJDIR)=0D + $(CC) -o $(OBJDIR)/main.o -c $(CFLAGS) main.c=0D +$(OBJDIR)/manage_data.o: manage_data.c=0D + @mkdir -p $(OBJDIR)=0D + $(CC) -o $(OBJDIR)/manage_data.o -c $(CFLAGS) manage_data.c=0D +$(OBJDIR)/workload.o: workload.c=0D + @mkdir -p $(OBJDIR)=0D + $(CC) -o $(OBJDIR)/workload.o -c $(CFLAGS) workload.c=0D +$(OBJDIR)/mxv.o: mxv.c=0D + @mkdir -p $(OBJDIR)=0D + $(CC) -o $(OBJDIR)/mxv.o -c $(CFLAGS) mxv.c=0D +=0D +$(OBJECTS): mydefs.h=0D +=0D +.c.o:=0D + $(CC) -c -o $@ $(CFLAGS) $<=0D +=0D +check:=0D + @echo "Running $(EXE) in $(EXPDIR)"=0D + @./$(EXPDIR)/$(EXE) -m 1000 -n 1500 -t 2=0D +=0D +install: $(BINDIR)/$(EXE)=0D + @/bin/cp $(BINDIR)/$(EXE) $(EXPDIR)=0D + @echo "Installed $(EXE) in $(EXPDIR)"=0D +=0D +clean:=0D + @/bin/rm -f $(BINDIR)/$(EXE)=0D + @/bin/rm -f $(OBJECTS)=0D +=0D +veryclean:=0D + @make clean=0D + @/bin/rm -f $(EXPDIR)/$(EXE)=0D diff --git a/gprofng/examples/mxv-pthreads/src/main.c b/gprofng/examples/mx= v-pthreads/src/main.c new file mode 100644 index 00000000000..625c60484d1 --- /dev/null +++ b/gprofng/examples/mxv-pthreads/src/main.c @@ -0,0 +1,374 @@ +/* Copyright (C) 2021-2023 Free Software Foundation, Inc. + Contributed by Oracle. + + This file is part of GNU Binutils. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +/* +* ------------------------------------------------------------------------= ----- +* This program implements the multiplication of an m by n matrix with a ve= ctor +* of length n. The Posix Threads parallel programming model is used to +* parallelize the core matrix-vector multiplication algorithm. +* ------------------------------------------------------------------------= ----- +*/ + +#include "mydefs.h" + +int main (int argc, char **argv) +{ + bool verbose =3D false; + + thread_data *thread_data_arguments; + pthread_t *pthread_ids; + + int64_t remainder_rows; + int64_t rows_per_thread; + int64_t active_threads; + + int64_t number_of_rows; + int64_t number_of_columns; + int64_t number_of_threads; + int64_t repeat_count; + + double **A; + double *b; + double *c; + double *ref; + + int64_t errors; + +/* +* ------------------------------------------------------------------------= ----- +* Start the ball rolling - Get the user options and parse them. +* ------------------------------------------------------------------------= ----- +*/ + (void) get_user_options ( + argc, + argv, + &number_of_rows, + &number_of_columns, + &repeat_count, + &number_of_threads, + &verbose); + + if (verbose) printf ("Verbose mode enabled\n"); + +/* +* ------------------------------------------------------------------------= ----- +* Allocate storage for all data structures. +* ------------------------------------------------------------------------= ----- +*/ + (void) allocate_data ( + number_of_threads, number_of_rows, + number_of_columns, &A, &b, &c, &ref, + &thread_data_arguments, &pthread_ids); + + if (verbose) printf ("Allocated data structures\n"); + +/* +* ------------------------------------------------------------------------= ----- +* Initialize the data. +* ------------------------------------------------------------------------= ----- +*/ + (void) init_data (number_of_rows, number_of_columns, A, b, c, ref); + + if (verbose) printf ("Initialized matrix and vectors\n"); + +/* +* ------------------------------------------------------------------------= ----- +* Determine the main workload settings. +* ------------------------------------------------------------------------= ----- +*/ + (void) get_workload_stats ( + number_of_threads, number_of_rows, + number_of_columns, &rows_per_thread, + &remainder_rows, &active_threads); + + if (verbose) printf ("Defined workload distribution\n"); + + for (int64_t TID=3Dactive_threads; TID threads, with the number of threads specified on the commandli= ne, +* or the default if the -t option was not used. +* +* Per the pthread_create () call, the threads start executing right away. +* ------------------------------------------------------------------------= ----- +*/ + for (int TID=3D0; TID] " \ + "[-n ] " \ + "[-t SMALL) + { + relerr =3D fabs ((c[i]-ref[i])/ref[i]); + } + else + { + relerr =3D fabs ((c[i]-ref[i])); + } + if (relerr <=3D TOL) + { + marker[i] =3D ' '; + } + else + { + errors++; + marker[i] =3D '*'; + } + } + if (errors > 0) + { + printf ("Found %ld differences in results for m =3D %ld n =3D %ld:\n", + errors,m,n); + for (int64_t i=3D0; ido_work; + int64_t repeat_count =3D local_data->repeat_count; + int64_t row_index_start =3D local_data->row_index_start; + int64_t row_index_end =3D local_data->row_index_end; + int64_t m =3D local_data->m; + int64_t n =3D local_data->n; + double *b =3D local_data->b; + double *c =3D local_data->c; + double **A =3D local_data->A; + + if (do_work) + { + for (int64_t r=3D0; r +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct thread_arguments_data { + int thread_id; + bool verbose; + bool do_work; + int64_t repeat_count; + int64_t row_index_start; + int64_t row_index_end; + int64_t m; + int64_t n; + double *b; + double *c; + double **A; +}; + +typedef struct thread_arguments_data thread_data; + +void *driver_mxv (void *thread_arguments); + +void __attribute__ ((noinline)) mxv_core (int64_t row_index_start, + int64_t row_index_end, + int64_t m, + int64_t n, + double **restrict A, + double *restrict b, + double *restrict c); + +int get_user_options (int argc, + char *argv[], + int64_t *number_of_rows, + int64_t *number_of_columns, + int64_t *repeat_count, + int64_t *number_of_threads, + bool *verbose); + +void init_data (int64_t m, + int64_t n, + double **restrict A, + double *restrict b, + double *restrict c, + double *restrict ref); + +void allocate_data (int active_threads, + int64_t number_of_rows, + int64_t number_of_columns, + double ***A, + double **b, + double **c, + double **ref, + thread_data **thread_data_arguments, + pthread_t **pthread_ids); + +int64_t check_results (int64_t m, + int64_t n, + double *c, + double *ref); + +void get_workload_stats (int64_t number_of_threads, + int64_t number_of_rows, + int64_t number_of_columns, + int64_t *rows_per_thread, + int64_t *remainder_rows, + int64_t *active_threads); + +void determine_work_per_thread (int64_t TID, + int64_t rows_per_thread, + int64_t remainder_rows, + int64_t *row_index_start, + int64_t *row_index_end); + +void mxv (int64_t m, + int64_t n, + double **restrict A, + double *restrict b, + double *restrict c); + +void print_all_results (int64_t number_of_rows, + int64_t number_of_columns, + int64_t number_of_threads, + int64_t errors); + +extern bool verbose; + +#endif diff --git a/gprofng/examples/mxv-pthreads/src/workload.c b/gprofng/example= s/mxv-pthreads/src/workload.c new file mode 100644 index 00000000000..fca0e8115e2 --- /dev/null +++ b/gprofng/examples/mxv-pthreads/src/workload.c @@ -0,0 +1,91 @@ +/* Copyright (C) 2021-2023 Free Software Foundation, Inc. + Contributed by Oracle. + + This file is part of GNU Binutils. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include "mydefs.h" + +/* +* ------------------------------------------------------------------------= ----- +* This function determines the number of rows each thread will be working = on +* and also how many threads will be active. +* ------------------------------------------------------------------------= ----- +*/ +void get_workload_stats (int64_t number_of_threads, + int64_t number_of_rows, + int64_t number_of_columns, + int64_t *rows_per_thread, + int64_t *remainder_rows, + int64_t *active_threads) +{ + if (number_of_threads <=3D number_of_rows) + { + *remainder_rows =3D number_of_rows%number_of_threads; + *rows_per_thread =3D (number_of_rows - (*remainder_rows))/number_of_= threads; + } + else + { + *remainder_rows =3D 0; + *rows_per_thread =3D 1; + } + + *active_threads =3D number_of_threads < number_of_rows + ? number_of_threads : number_of_rows; + + if (verbose) + { + printf ("Rows per thread =3D %ld remainder =3D %ld\n", + *rows_per_thread, *remainder_rows); + printf ("Number of active threads =3D %ld\n", *active_threads); + } +} + +/* +* ------------------------------------------------------------------------= ----- +* This function determines which rows each thread will be working on. +* ------------------------------------------------------------------------= ----- +*/ +void determine_work_per_thread (int64_t TID, int64_t rows_per_thread, + int64_t remainder_rows, + int64_t *row_index_start, + int64_t *row_index_end) +{ + int64_t chunk_per_thread; + + if (TID < remainder_rows) + { + chunk_per_thread =3D rows_per_thread + 1; + *row_index_start =3D TID * chunk_per_thread; + *row_index_end =3D (TID + 1) * chunk_per_thread - 1; + } + else + { + chunk_per_thread =3D rows_per_thread; + *row_index_start =3D remainder_rows * (rows_per_thread + 1) + + (TID - remainder_rows) * chunk_per_thread; + *row_index_end =3D remainder_rows * (rows_per_thread + 1) + + (TID - remainder_rows) * chunk_per_thread + + chunk_per_thread - 1; + } + + if (verbose) + { + printf ("TID =3D %ld row_index_start =3D %ld row_index_end =3D %ld\n= ", + TID, *row_index_start, *row_index_end); + } +} --=20 2.31.1